Scrolling with mouse

Get help using Construct 2

Post » Fri Mar 01, 2013 12:00 pm

Hello! I tried looking through the FAQ, but didn't find something that quite helped me. Maybe I overlooked it, but here is what I'm trying to do:

Rather than have the camera, follow a specific sprite or arrowkey, I'd like to scroll the 'map' by moving the mouse to the edges of the screen. As is seen in some strategy games.

Is there some fancy way of achieving this that I have missed?
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Fri Mar 01, 2013 12:13 pm

Two quick ideas :

a) Invisible sprites at the edges of screen (parallax 0) and conditions to scroll the screen when mouse is overlapping them.

b) Check each tick for absolute mouse position to detect if it's near edge of the screen.

After you've detected where you wish to scroll, there are nice examples of how to scroll the screen in the FAQ thread. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Mar 01, 2013 1:47 pm

I had not thought of the invisible sprite idea, I think I'll try that out for now, thanks!

If people have other interesting ideas for the problem, do keep sharing.
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Sun Aug 04, 2013 11:59 am

Here's a working script:

http://imgur.com/Q5pbMnY

Remove the key conditions if you don't also want scrolling with wasd-keys.

ScrollRate is how fast the screen scrolls in pixels each tick.
MouseScrollArea is how large the trigger areas are at the sides.

The advantage of this solution is that it's easy to copy-and-paste between projects and supports diagonal scrolling.
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Mon Sep 23, 2013 6:36 pm

Oh, thank you very much! Looks like this will work better than what I had put in place.
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Mon Sep 23, 2013 6:39 pm

Only just saw this post but yep I used an invisible sprite with ScrollTo behaviour that teleports to Mouse.X,Mouse.Y Every Tick..
B
33
S
9
G
48
Posts: 1,560
Reputation: 29,154

Post » Mon Sep 23, 2013 6:55 pm

I'm still looking for the perfect solution for my game, I've gone through several. (assigning and sending armies on an isometric map with pop up windows)

Having the screen center on the cursor was prettiest, (scrollto the mouse each tick) but was annoying when opening and closing windows because the screen would snap to the cursor location. (letting the screen scroll under the windows made you feel dizzy, so it locked with them open.)

Touching the edges felt logical, but felt jarring because it didn't ease in and out like I wanted. Plus, if you played in a window it would stop scrolling if your cursor ventured over the edge.

I also used the invisible sprite with scrollto behavior, and had it chase the mouse rather than teleport. It still moved too much when trying to work.

Right now I have it scrolling a speed set by the distance from the edge, but it's annoying because you accidentally scroll the screen when trying to click something near the edge, and it makes you miss.

I will probably end up with almost touching the edge adds to a variable, and the value of the variable determines the speed of the scroll. Still have the problem of the cursor venturing too far and stopping though.

Edit: Just stepped back and looked at it fresh because of this thread, and I think I have a different direction. I'm using the Touch drag demo for another game, and it works fine for the mouse as well. You click an non-clickable spot on the map and pull it to move it.
Paradox2013-09-23 19:05:49
B
200
S
51
G
30
Posts: 896
Reputation: 36,494


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests