This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-04 15:30:39

The_Scratch
Scratcher
Registered: 2012-04-19
Posts: 100+

scrolling for noobs

Okay, so Im making a game creator game http://scratch.mit.edu/projects/TheScratchTest/2713675
And I've got most of it down, but im wondering about scrolling. I want it to scroll both ways when you're playing as a character, and I also want it to scroll by a scroll bar when you're editing the level. Scrolling is actually very complicated. With all the velocity and stuff. So if you could please explain it as if you were explaining it to a 5 year old for me I would appreciate it. Please, do not post any engines.


when gf clicked
repeat until <helped>
   HELP ME!!!!!]
end


Little known fact. You are acting cray cray.
http://24.media.tumblr.com/tumblr_mc0udwsMCj1r3l41yo1_400.gif

Offline

 

#2 2012-08-04 16:30:36

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: scrolling for noobs

The wiki scrolling article can probably explain it better than I can.  For the scroll bar, you essentially make the scrollX variable a function of the x position of the scroll bar.  I'm not sure if yours is positive or negative, but is should look something like this:

set [scrollX v] to (((x position)+(240))*(scale))


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2012-08-04 17:58:47

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: scrolling for noobs

You could have a scroll bar, or use the mouse to scroll (by holding down and dragging). This might be useful if you can scroll x and y too. For x and y scrolling, you could just use Pythagorus' theorem and/or trig.

This would give an effect like on iPods where the user can 'drag to scroll'.

1) Work out the position that the user clicks first.
2) Find the x and y components of their mouse movement. This can be done by taking the current position of the mouse away from the original.
3) FInally, scale up/down to however sensitive you want the movements to be.

The final script would look something like this:


when gf clicked
forever
if <<(editing) = (true)> and <mouse down?>>
set [xpos v] to (mouse x)
set [ypos v] to (mouse y)
set [memoryX v] to (ScrollX)
set [memoryY v] to (ScrollY)
repeat until < not <mouse down?>>
set [dx v] to ((xpos) - (mouse x))
set [dy v] to ((ypos) - (mouse y))
set [scrollX v] to ((memoryX) + ((dx) * (scale)))
set [scrollY v] to ((memoryY) + ((dy) * (scale)))
end

Last edited by Prestige (2012-08-04 17:59:57)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

Board footer