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

#1 2009-08-03 16:16:08

Reamm
Scratcher
Registered: 2007-11-10
Posts: 100+

How to scroll X and Y

Scrolling X position and Y position
First make a variable named ScrollX and a other one called ScrollY
Make a character sprite with the following scripts

<when[ Up ]key pressed>
<change{ ScrollY }by( -10

<when[ Down ]key pressed>
<change{ ScrollY }by( 10

<when[ Right ]key pressed>
<change{ ScrollX }by( -10

<when[ Left ]key pressed>
<change{ ScrollX }by( 10

While making these scripts you can change how fast you want your character to scroll by changing the 10 on the scripts to whatever number you like.

Next make a sprite called terrain 0
with the following script


<when green flag clicked>
<forever>
<set x to( (( < { ScrollX }> <+> (( 460 <*> 0 )) ))
<set y to( (( < { ScrollY }> <+> (( 360 <*> 0 )) ))

Next make a sprite called terrain 1
with the script

<when green flag clicked>
<forever>
<set x to( (( < { ScrollX }> <+> (( 460 <*> 0 )) ))
<set y to( (( < { ScrollY }> <+> (( 360 <*> 0 )) ))

The zeros at the top could be edited to -1 , 1 anything and thats the  X and Y pos of the sprite.

If you dont understand download this game and check the sprites
http://scratch.mit.edu/projects/Reamm/633116

Offline

 

#2 2009-08-05 21:51:18

sanda427
Scratcher
Registered: 2008-12-02
Posts: 96

Re: How to scroll X and Y

Thanks, That was very helpful for a scrolling game I'm making.


http://squiby.net/view/2246392.png

Offline

 

#3 2009-08-06 05:27:36

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How to scroll X and Y

Very helpful!  Thanks for sharing.

I think you could get a slightly faster result if you used a single GOTO block instead of the two SET X and SET Y blocks. I haven't done any time trials...but it should be quicker to run one block instead of two  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2009-08-06 11:10:38

GrammaticlyCorrect
Scratcher
Registered: 2008-11-18
Posts: 42

Re: How to scroll X and Y

Does setting scroll x to 460 work properly? Because I know the length of the Scratch screen is 480 pixels.

Anyways, nice little guide you've made here.  big_smile

Offline

 

#5 2009-08-06 11:28:21

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: How to scroll X and Y

GrammaticlyCorrect wrote:

Does setting scroll x to 460 work properly? Because I know the length of the Scratch screen is 480 pixels.

Anyways, nice little guide you've made here.  big_smile

It should be 480


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#6 2009-08-06 11:41:40

fireball123
Scratcher
Registered: 2008-05-08
Posts: 1000+

Re: How to scroll X and Y

instead of using <when[up]key pressed>
which is very crude and not very smooth, I recommend you use a script like
<when green flag clicked>
<forever>
<if><key[ up ]pressed?>
<change{ Yscroll }by( 5
<end>
<if><key[ down ]pressed?>
<change{ Yscroll }by( -5
<end>
<if><key[ right ]pressed?>
<change{ Xscroll }by( 5
<end>
<if><key[ left ]pressed?>
<change{ Xscroll }by( -5
<end>
<end>

Last edited by fireball123 (2009-08-06 11:45:59)


I did it for the Lolz

Offline

 

Board footer