How do I drag camera around with mouse.

1 favourites
  • 11 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hey everyone =)

    I've been wondering how could I properly drag the camera around, like many Moba or RTS games do.

    I've been trying to do this for a while. Best I could come up with was to store Mouse.Absolute coordinates and Scroll coordinates on 4 variables, and then use those in "Old Scroll Coordinates + (Old Mouse.Absolute Coordinates - Current Mouse.Absolute Coordinates)" which gives me an ok result.

    CAPX

    My main complain with this way of doing it, is that I cannot control the drag speed, nor am I able to invert it if needed.

    Any help is always appreciated =)

  • There is an RTS template in C2 that might help with mouse scrolling, this might be able to be adapted so you can drag and change the speed of the dragging, might be worth looking at if you haven't already.

    Regards

    Sunny

  • Just thinking out loud:

    Why not create a sprite with a movement behaviour and have it move to the mouse coordinates?

    Use system scrollto to scrollto the sprite when needed and you can tweak the scrolling speed with the movement behaviour..

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Just thinking out loud:

    Why not create a sprite with a movement behaviour and have it move to the mouse coordinates?

    Use system scrollto to scrollto the sprite when needed and you can tweak the scrolling speed with the movement behaviour..

    You could make a nice set of cursors then too.

  • Sunny87 The template uses the mouse on border kind of movement. it's of no use to me =(

    LittleStain Because that do not behave like I want to, I need to DRAG the camera, not PAN the camera =(

  • Sunny87 The template uses the mouse on border kind of movement. it's of no use to me =(

    LittleStain Because that do not behave like I want to, I need to DRAG the camera, not PAN the camera =(

    I understand, that's why I gave this idea to limit drag-speed..

    Or are you going to tell the person playing not to drag too fast?

  • I've never made an RTS but is there not a way that the background or in this case the floor can be clicked then set compare direction in some way?

  • LittleStain there has to be a speed and invert option.

    Sunny87 Well, yeah, and that would be what I told I had already done

    At this point i'm worried the amount of answers on this post will dissuade people to actually enter and give a real answer. I appreciate the intention, but maybe don't post a random guess when people are asking for help =/

  • Sargas I am not sure what you mean by "invert option"

    but what I do is create a sprite called Camera and give it the ScrollTo ability.

    You can then manually move the Camera sprite in relation to how you drag the mouse (the way you do in your capx) or you can pin it to a player, or you can use lerp or other ways to program it to move by itself.

    Because the Camera is a sprite, you can scale the way you move it to get different speeds, or what ever other effect you want.

    You can take a look at a test project I have been playing with (Angry Birds type game)... I have the Camera (green square) visible so I can tell where it is and what it is doing.

    each level (there are only 2) starts by showing the structure you have to knock down, then pans to the slingshot. You can manually drag the camera around instead (and that cancels the automatic pan). Once you launch a bird, the camera follows the bird unit it stops moving - than pans back to the slingshot.

    There is a button on the screen to change the magnification, but usually (in other projects) I use the scroll wheel on the mouse to zoom in or out to where the mouse is pointed to.

    You can see it in action here: http://www.rieperts.com/games/birds/

    you can get the capx here: (code is very messy because it is experimental, and it requires the Chipmunk Physics plugin) http://www.rieperts.com/games/forum/angry_birds_chipmunk.capx

  • This one worked for us:

    https://www.scirra.com/tutorials/415/dr ... -and-touch

    We combined it with a full mouse zoom capacity, which caused some weird issues with the pan that we have yet to fix, but it works nicely otherwise.

  • AllanR Thank =), but that's what I already managed to do. If you see my capx, you'll see it has the same behavior =)

    By inverted I mean you can either drag the terrain or the camera. So in one mode; dragging down, makes the camera go up, and in another mode, the camera goes down.

    Just to be clear I need the camera drag to work like the camera on StarCraft 2 or Heroes of the Storm.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)