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

#1 2012-06-17 00:45:03

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

1 Sprite Scrolling

I have seen users like AB3 and Wes64 use this, but I don't understand the mechanics.  I know it has to do with stamping, but I don't know how to program it.  Can someone help?
Thanks!


http://i47.tinypic.com/2iaa73k.png

Offline

 

#2 2012-06-17 04:59:29

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: 1 Sprite Scrolling

Okay, you're going to need a variable called xscroll for the scrolling amount. Then, you need to do this:

when clicked
hide
The stamping will do all of the work.
forever
clear
Remove all previous stamps or pen marks.
if
key
left arrow
pressed?
and
scrollx
<
0
change
scrollx
by
1
You can change this to 2, 3, 4, or 6.
if
key
right arrow
pressed?
and
scrollx
>
-480
Limits scrolling to 480 pixels, or 2 backgrounds.
change
scrollx
by
-1
The same as above, but negative.
switch to costume
costume1
The first background.
if
scrollx
<
480
If the first background will be in the screen.
go to x:
scrollx
y:
0
stamp
switch to costume
costume2
The second background.
if
scrollx
>
0
If the second background will be in the screen.
go to x:
scrollx
+
480
*
1
y:
0
stamp

That's a very basic 2-background scroller. If you want it to be longer, I'll post a solution to that.


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#3 2012-06-17 11:29:44

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: 1 Sprite Scrolling

Could you tell me how to extend it?


http://i47.tinypic.com/2iaa73k.png

Offline

 

#4 2012-06-17 12:09:20

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: 1 Sprite Scrolling

berberberber wrote:

Could you tell me how to extend it?

Okay!

You start with this:

when clicked
hide
forever
clear
if
key
left arrow
pressed?
and
scrollx
<
0
change
scrollx
by
1
You can change this to 2, 3, 4, or 6.
if
key
right arrow
pressed?
and
scrollx
<
960
Set this number to ((your amount of backgrounds minus 1) times 480)
change
scrollx
by
-1
The same as above, but negative.

Okay, now, the first one's scripts:
switch to costume
costume1
Your first background.
if
scrollx
<
-480
go to x:
scrollx
y:
0
stamp

Add that at the end of the forever loop.
Now, for each of the other ones (except the last one), we need to add this to the end of the forever loop:
switch to costume
costume2
Set this to the correct one.
if
scrollx
<
0
and
scrollx
>
-960
Change these numbers by -480 for each background.
go to x:
scrollx
+
480
*
1
y:
0
Change the 1 by 1 for each background.
stamp

No, finally, for the last one. Just add this to the end of the forever loop:
switch to costume
costume3
Your last background.
if
scrollx
>
-480
Set this to (((amount of backgrounds minus 1) times 480) times -1)
go to x:
scrollx
+
480
*
2
y:
0
Set the 2 to the amount of backgrounds - 1.
stamp

All done! I'm sorry if I didn't explain it well. I hope this helps!

IMPORTANT: Test it in Presentation Mode.

Last edited by SciTecCf (2012-06-17 13:47:47)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#5 2012-06-17 15:33:52

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: 1 Sprite Scrolling

If you want to extend it into infinite, you should use the "mod" block.  Basically, the mod block gives you the remainder after dividing the first number by the second.  You have to think about it a bit before it makes sense:
-you want 2 stamps/positions.
-each one must be able to travel from one side to the other and then loop around
next, get into the math:
-since each scene is a full screen (480 pixels long) and the screen is 480 pixels long, in order for it to completely exit the screen on both sides, it must travel from x=480 to x=-480
-480*2=960 is thus the number we will use for the modulus or mod block.

so far we have:

go to x:
scrollx
mod
960
y:
0

but this will make our sprite travel from 960 to 0 and then loop back to 960, so we have to make it:
go to x:
scrollx
mod
960
-
480
y:
0

instead.
There's one of the scenes done, but we need a second in order to keep the screen filled the whole time. Right now we've got one that's going to -480 when scrollx = 0 so you need one going to 0 when scrollx = 0 but also cycles from 480 to -480:
go to x:
scrollx
+
480
mod
960
-
480
y:
0

should do the trick.

Last edited by AtomicBawm3 (2012-06-17 15:34:46)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#6 2012-06-17 16:11:27

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: 1 Sprite Scrolling

Thanks, but could you sho me the whole script, AB3?


http://i47.tinypic.com/2iaa73k.png

Offline

 

#7 2012-06-17 16:34:58

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: 1 Sprite Scrolling

berberberber wrote:

Thanks, but could you sho me the whole script, AB3?

Sure:

when clicked
set
sx
to
0
forever
switch to costume
go to x:
sx
*
-1
+
480
mod
960
-
480
y:
0
stamp
switch to costume
go to x:
sx
*
-1
mod
960
-
480
y:
0
stamp

This is what I used for Dark and Light.

Sorry...You can't see the math for the costume numbers:
just odds:
(round(sx/960)*2)+1
Just evens:
(round((sx+480)/960)-1)*2)+2

Last edited by AtomicBawm3 (2012-06-17 16:38:29)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#8 2012-06-17 17:41:41

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: 1 Sprite Scrolling

Is it something like this?

When clicked
forever
switch to
costume 1
go to x:
cos1 x
y:
cos1 y
stamp
if
change
cos1x
by
1
if
change
cos1 y
by
-1

And then you just do as many costumes and sensing scripts as you need?


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

Board footer