Scrolling Demo

Post your own tutorials, guides and demos.

Post » Fri Jan 30, 2009 3:55 pm

So I was thinking, "I want a map layout that I can scroll around". Soon I realized that just "Scroll to MouseXY" just won't do, as it instantly focuses the screen on mouse coordinates.

After a bit of reinventing the wheel, I've come up with a smooth layout scrolling solution. See the attached cap. Just hold left mouse button to scroll around.

I dare you to find a more elegant solution! All is fair in love, war and development. ;)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Fri Jan 30, 2009 4:06 pm

Awesome, one event too!
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Jan 31, 2009 8:12 am

ScrollX-distance(MouseX,MouseY,ScrollX,ScrollY)/32*cos(angle(MouseX, MouseY, ScrollX, ScrollY))

I'm sure that can be simplified...
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Sat Jan 31, 2009 8:15 am

It can be simplified to just:

lerp(ScrollX,MouseX,0.03)
lerp(ScrollY,MouseY,0.03)

The 0.03 affects the speed...0.03 is about 1/32...
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Sat Jan 31, 2009 8:16 am

Hm, I feel so silly now that I look at it with rested brains. I should just have taken the difference between ScrollX and MouseX then substract it from the ScrollX!

ScrollX-(ScrollX-MouseX)*0.03 (horizontal scrolling speed)
ScrollY-(ScrollY-MouseY)*0.04 (vertical scrolling speed)

Since I can't seem to edit my initial post, I'll just upload the updated cap here.

Edit: Oh, so that is what lerp does!
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Jan 31, 2009 11:29 am

Yep :) Never the less, its a nice way to scroll around, anyone making their own level editors should use that event rather than trying to create scrollbars or something (which is harder to make, and less intuative to use)
B
4
S
2
G
5
Posts: 641
Reputation: 3,011


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests