How do I drag camera around with mouse.

Get help using Construct 2

Post » Wed Aug 12, 2015 6:15 am

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 =)
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Wed Aug 12, 2015 7:56 am

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
B
5
S
1
Posts: 12
Reputation: 363

Post » Wed Aug 12, 2015 8:09 am

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 12, 2015 8:54 am

LittleStain wrote: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.
B
5
S
1
Posts: 12
Reputation: 363

Post » Wed Aug 12, 2015 8:59 am

@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 =(
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Wed Aug 12, 2015 9:05 am

Sargas wrote:@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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 12, 2015 9:32 am

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?
B
5
S
1
Posts: 12
Reputation: 363

Post » Wed Aug 12, 2015 2:15 pm

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

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

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 =/
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Wed Aug 12, 2015 9:19 pm

@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
Last edited by AllanR on Wed Aug 12, 2015 9:26 pm, edited 1 time in total.
B
98
S
35
G
20
Posts: 438
Reputation: 17,875

Post » Wed Aug 12, 2015 9:24 pm

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.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests