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

#1 2009-04-03 20:47:18

mouseytaco
Scratcher
Registered: 2009-02-26
Posts: 23

How do I learn about the scrolling effect?

Twisted Ninja, Kirby Scroller, and games like that I really envy. I wish I knew how to do it. Please tell me if you know!

Offline

 

#2 2009-04-03 21:07:21

demosthenes
Retired Community Moderator
Registered: 2008-02-19
Posts: 1000+

Re: How do I learn about the scrolling effect?

http://scratch.mit.edu/forums/viewtopic.php?id=2440


I've taken a long hiatus, but I still visit sometimes. Give me some time to answer any messages you post on my projects!

Offline

 

#3 2009-04-04 21:25:11

mouseytaco
Scratcher
Registered: 2009-02-26
Posts: 23

Re: How do I learn about the scrolling effect?

Awesome game. But my computer couldn't download.
Could you tell me which blocks to snap together?

Offline

 

#4 2009-04-05 07:11:13

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

Re: How do I learn about the scrolling effect?

Here is a good scrolling tutorial that might help you out

http://scratch.mit.edu/forums/viewtopic.php?id=2440


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

Offline

 

#5 2009-04-06 09:34:43

Stickman704
Scratcher
Registered: 2009-01-31
Posts: 1000+

Re: How do I learn about the scrolling effect?

archmage wrote:

I am going to try and explain how to scroll stuff in scratch but you better be good at programming in scratch before you try this. I do not recommend a scrolling game as your first project.

There are 2 methods of scrolling I use. Method 1 uses many sprites, is easy to implement but can cause lag if the area is too large. Method 2 uses just 2 sprites but does not lag.

METHOD 1: SCROLLING WITH MANY SPRITES
For a demonstration of this method go to http://scratch.mit.edu/projects/archmage/76150

Ok first create a new variable called scrollX

        <{  scrollX  }>

Now that we have that we will need to have our scrolling sprites.
So make a sprite called terrian0.

*It is important to name the sprite terrain0 instead of terrain1 to check and adjust a value used to scroll.*

Now some of these numbers may vary in value depending on the size of your sprite. This assumes your sprite is as wide as the screen.

The number 480 in this code block represents the stage's total width.

//This should be placed on the sprite "terrain0"
<when green flag clicked>

<forever>
<set x to( (( <{ scrollX }>  <+>  ((  480 <*>  0 )) ))

Now the 480 * 0 bit is not necessary in the first sprite you want to scroll but we will keep it in there so we can use it when we duplicate the sprite using the duplicate tool. What that number actually represents is the number at the end of the sprite's name so for the sprite terrain1 you would put

<forever>
<set x to( (( <{ scrollX }>  <+>  ((  480 <*>  1 )) ))

and for terrain2 you would put a 2 instead of a 1 and so on.

Now the number at the end of the sprites name will dictate the order of the sprites so if you keep moving right you will first see terrain1 then terrain2 then terrain3 ect.


now here is a simple script that demonstrates how to alter the scrollX variable to make your sprites scroll.
This code should be placed on the stage. Using this code on multiple sprites is not necessary and not recommended.

<when green flag clicked>

<forever if> <key[ right arrow  ]pressed?>
<change{  scrollX }by( 5


<forever if> <key[ left arrow  ]pressed?>
<change{  scrollX }by( -5

METHOD 2:SCROLLING WITH 2 SPRITES
For a demonstration of this method go to http://scratch.mit.edu/projects/archmage/82995

You should already be comfortable using the first scrolling method as this method is more difficult

You will need to create 3 different variables for this method

  <{  scrollX  }>    //This variables keeps track of how far the user has scrolled

  <{ terrainNum  }>  //This is used to let the terrain sprite know what terrain should be displayed
 
<{  xVelocity  }>  //For some reason I was unable to get linear movement to make the terrain sprite not flicker with this method. However when the scrolling variable is changed according to the xVelocity variable the scrolling works as it should and does not flicker.

*Place these scripts on the stage*

<when green flag clicked>
<forever>
<if>  <( (( <round( <{ scrollX }>  </> 480 )) <>> (( <{ scrollX }>  </> 480 )) )>
<set{ terrainNum }to( (( <round(  (( <{ scrollX }>  </> -480 )) <+> 1 ))
<else>
<set{ terrainNum }to( <round(  (( <{ scrollX }>  </> -480 ))

What this script does is it divides the scroll variable by the stage's width and then rounds it down to the nearest whole number.

<when green flag clicked>
<forever>
<if> <key[ right arrow ]pressed?>
<change{ xVelocity }by( -2
<end>
<if> <key[ left arrow ]pressed?>
<change{ xVelocity }by( 2
<end>
<set{ xVelocity }to(  (( <{ xVelocity }> <*> 0.9  ))
<change{ scrollX }by( <{ xVelocity }>
<end>

This is a basic movement code that uses the xVelocity variable to change the scrollX variable.


Now before we begin programming on the terrain sprites it is very important to remember that BOTH of the two terrain sprites must have exactly the same costumes in exactly the same order. Now doing this will result in weird changing of the terrain sprites to incorrect costumes.

Make sure you have created 2 terrain sprites called "terrain1" and "terrain2".

Now put this code on terrain1.

<when green flag clicked>
<forever>
<switch to costume[ <{ terrainNum }>
<set x to( (( <{ scrollX  }> <+>  (( 480 <*> (( <{ terrainNum }> <-> 1 )) ))))
<end>

What this script does is it sets it's costume according to the terrainNum variable and then it sets it's x position to scrollX+(480*(terrainNum-1)). When the terrainNum variable changes it makes the terrain scripts change costumes accordingly and move to the proper position.

Now put this code on terrain2.

<when green flag clicked>
<forever>
<switch to costume[ (( <{ terrainNum }> <+> 1 ))
<set x to( (( <{ scrollX  }> <+>  (( 480 <*> <{ terrainNum }> ))))
<end>

This script is similar to the script on the first terrain sprite but it has been altered to appear in front of the terrain1 sprite.

Both methods when used correctly will produce a scrolling effect.

If you want to see examples of projects that feature scrolling go to this gallery.
http://scratch.mit.edu/galleries/view/8494


Dun dun dun dun dun dun.... dun dun dun dun dun dun...  tongue

Offline

 

#6 2009-04-06 20:44:24

mouseytaco
Scratcher
Registered: 2009-02-26
Posts: 23

Re: How do I learn about the scrolling effect?

Thank you so much, Paddle2see. I now made my demo of the game fat cat on nitrome!http://scratch.mit.edu/projects/mouseytaco/479576
smile

Offline

 

#7 2009-04-07 06:47:52

bosox397
Scratcher
Registered: 2008-02-17
Posts: 1000+

Re: How do I learn about the scrolling effect?

cool! hey you remembered my game! even more awesome


Dear Scratch Users,
I'm done with scratch, or at least making projects. I have made one last big game, thats both fun and teaches a lesson about water. It'd mean a lot if you gave me feedback.                              http://scratch.mit.edu/projects/bosox397/569201

Offline

 

#8 2009-04-07 13:27:17

mouseytaco
Scratcher
Registered: 2009-02-26
Posts: 23

Re: How do I learn about the scrolling effect?

I like Smiley the best because you can move way faster than the guy in jail break.

Offline

 

#9 2009-04-07 15:14:21

bosox397
Scratcher
Registered: 2008-02-17
Posts: 1000+

Re: How do I learn about the scrolling effect?

yAH ThanX. me 2


Dear Scratch Users,
I'm done with scratch, or at least making projects. I have made one last big game, thats both fun and teaches a lesson about water. It'd mean a lot if you gave me feedback.                              http://scratch.mit.edu/projects/bosox397/569201

Offline

 

#10 2009-04-13 12:10:06

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: How do I learn about the scrolling effect?

also, have a look at the tut in my sig. it explains more about exactly how it is scrolling

Offline

 

Board footer