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

#1 2007-12-07 15:10:30

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Scrolling Background - Help.

Basically I have no clue on how to make scrolling backgrounds and any tutorial/advice/info on how to do it would be very appreciated. Please don't post a link to a project which contains scrolling because even if I do download it I can't make head nor Tails of it. Any post explaining basically what is happening is sort of what I need.


Many Thanks.


Burn baby Burn!

Offline

 

#2 2007-12-07 16:19:14

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

Re: Scrolling Background - Help.

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

Last edited by archmage (2008-05-26 20:09:58)


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

 

#3 2007-12-07 21:01:12

funkymonkey
Scratcher
Registered: 2007-06-03
Posts: 1000+

Re: Scrolling Background - Help.

wow. that is cool. do you know how to make the backround scroll?


http://i243.photobucket.com/albums/ff67/hprules_photos/banner2.jpg
Kuzimu: Dawn of a New Age                                                                                                  Coming May 2010

Offline

 

#4 2007-12-07 22:03:41

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

Re: Scrolling Background - Help.

funkymonkey wrote:

wow. that is cool. do you know how to make the backround scroll?

Well the background has to be make of sprites. Just use the tutorial I typed out above.


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

 

#5 2007-12-08 05:41:05

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Re: Scrolling Background - Help.

Thanks very much archmage. I have taken my scratch projects to a whole new level. I really Apreciate it.

Thanks again,

messd002


Burn baby Burn!

Offline

 

#6 2007-12-08 05:55:51

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Re: Scrolling Background - Help.

Don't worry I have solved it. I wasn't changing it on all sprites.

Last edited by messd002 (2007-12-08 05:57:56)


Burn baby Burn!

Offline

 

#7 2007-12-08 09:46:43

Montymio
Scratcher
Registered: 2007-09-22
Posts: 1

Re: Scrolling Background - Help.

THANK YOU!!!!!

Offline

 

#8 2007-12-08 19:15:08

08jackt
Scratcher
Registered: 2007-09-12
Posts: 1000+

Re: Scrolling Background - Help.

yikes, thanx dudes. i didn't think i'd ever scroll, but using your tutorial i did!!!! thanx so much, i owe you one  smile


http://i39.tinypic.com/jgtswi.png

Offline

 

#9 2007-12-08 20:45:19

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

Re: Scrolling Background - Help.

It would be cool if you could post your scrolling projects here so that other people can see them and download them  smile

I'll post some of my scrolling projects.

Proper scrolling demo
http://scratch.mit.edu/projects/archmage/24624
This was my first scrolling attempt. It is coded kinda like in the tutorial but the code in the tutorial has been simplified.

1 way scrolling
http://scratch.mit.edu/projects/archmage/32358
This features seamless 1 way scrolling. It uses a different way of hiding sprites that uses layers.

perfect side scrolling engine
http://scratch.mit.edu/projects/archmage/28903
This is a side scrolling engine made in scratch. It is more complex because it changes from non-scrolling movement to scrolling movement for a mario-like effect.

mario recharged
http://scratch.mit.edu/projects/archmage/45066
This is a game I made using my side scrolling engine. It was pretty well received and got a lot of love its. However it does lag like crazy so I'll have to update my side scrolling engine for the sequel.

Last edited by archmage (2007-12-08 21:08:48)


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

 

#10 2007-12-09 04:52:29

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: Scrolling Background - Help.

these are my scrolling background games:
Mini Race
http://scratch.mit.edu/projects/bigB/15836
This is an aerial view game where you race a mini around a track.  The side scrolling works in 360degrees and changes depending on your speed.

Virtual Golf
http://scratch.mit.edu/projects/bigB/20317
In this golf game the srolling only goes from left to right (not up and down) depending on the angle and speed you hit the golf ball.

Naval Warfare
http://scratch.mit.edu/projects/bigB/21945
This is a two player warship game experiment where i tried to see if i could make a scrolling effect where both players could see the other in relation to themselves.  You can also fire your cannons and attempt to destroy the other ship.


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#11 2007-12-09 10:14:50

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

Re: Scrolling Background - Help.

I have just created a gallery for all scrolling projects. If you have a project that uses scrolling feel free to add to it  smile

http://scratch.mit.edu/galleries/view/8494


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

 

#12 2007-12-09 12:32:22

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Scrolling Background - Help.

Game with Vertical Scrolling: http://scratch.mit.edu/projects/Mayhem/16264
One of many games with horizontal scrolling:  http://scratch.mit.edu/projects/Mayhem/19961
Multi-directional scrolling: http://scratch.mit.edu/projects/Mayhem/30135
Freaky rotational scrolling:  http://scratch.mit.edu/projects/Mayhem/33629


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#13 2007-12-09 13:46:09

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Scrolling Background - Help.

archmage, you should make sure that you add any scrolling project that is mentioned in this thread.  You could also look through the old threads on scrolling for other projects, and check for the "scrolling" tag on projects.

Putting together a gallery that usefully gathers a lot of related projects can be a lot of work, but it is of great value to the community.

Offline

 

#14 2007-12-09 14:17:04

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

Re: Scrolling Background - Help.

I just made  a project that features multi directional scrolling and uses the new trig math functions.

It would be good for a car game or something like that
http://scratch.mit.edu/projects/archmage/64683


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

 

#15 2007-12-09 15:33:57

Gigabyte123
Scratcher
Registered: 2007-10-15
Posts: 100

Re: Scrolling Background - Help.

I just made a scrolling project that you are a jedi and you have to defeat darth nihilus. I found the scrolling pretty easy, but my version is a bit buggy because I wanted to release it on the internet too soon.


gather your confidence- reach for the skies... and always use deoderant!

Offline

 

#16 2007-12-10 13:03:16

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Re: Scrolling Background - Help.

here is the unfinished version of my minor scrolling project. Look for better stuff in the future.

http://scratch.mit.edu/projects/messd002/65113


Burn baby Burn!

Offline

 

#17 2007-12-10 13:57:00

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Re: Scrolling Background - Help.

How did this post get to be a sticky? God i am so proud for pratically no reason!

Last edited by messd002 (2007-12-10 13:59:14)


Burn baby Burn!

Offline

 

#18 2007-12-10 14:22:53

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Re: Scrolling Background - Help.

Archmage could you please check this post out:

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


Burn baby Burn!

Offline

 

#19 2007-12-10 14:34:18

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Scrolling Background - Help.

This thread was made sticky because requests for help on scrolling backgrounds are frequent, and the list of examples provided in this thread seemed worth keeping in people's short lists.  When the documentation wiki becomes the established way to provide this sort of information we'll probably unstick the thread.

Offline

 

#20 2007-12-10 16:32:28

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

Re: Scrolling Background - Help.

Ok Messd002 asked me how to do multidirectional scrolling so I will just post a code snipit  on how to scroll in the direction you are facing as shown in this project http://scratch.mit.edu/projects/archmage/64683

Also I am sorry that some of the code block in the snipit will be missing since they are from the new version of scratch so I will replace them with words.

For this code you need 4 variables. x, y, scrollY, and scrollX.
This will move if the mouse is down but you can change it.

//place on main player sprite
<when green flag clicked>
<forever>
<if><mouse down?>
<change{ scrollX  }by( ((  x <*> -1 ))
<change{ scrollY  }by( ((  y <*> -1 ))
<set{ x  }to(  sin of   <direction>
<set{  y }to(  cos of <direction>
<end>
<point towards( mouse pointer
<end>


Also it would be cool if some one could put the scrolling projects gallery as featured on the front page  smile
http://scratch.mit.edu/galleries/view/8494

Last edited by archmage (2007-12-10 17:14:21)


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

 

#21 2007-12-17 08:39:47

supercooldamian
Scratcher
Registered: 2007-12-16
Posts: 9

Re: Scrolling Background - Help.

messd002 wrote:

Basically I have no clue on how to make scrolling backgrounds and any tutorial/advice/info on how to do it would be very appreciated. Please don't post a link to a project which contains scrolling because even if I do download it I can't make head nor Tails of it. Any post explaining basically what is happening is sort of what I need.


Many Thanks.

give me a idea of background so I can have a cool background

Offline

 

#22 2007-12-17 08:40:50

supercooldamian
Scratcher
Registered: 2007-12-16
Posts: 9

Re: Scrolling Background - Help.

I need a cool background so teach me how to get one




thanks people

Offline

 

#23 2007-12-17 10:09:39

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Scrolling Background - Help.

Hello,

I also have a scrolling background.

RCRacing 3D v 1.1
I don't use the system archmage explained on top of this page, bu a system from Jens' project Big. The scripts are much more easy. Just place all rotation points in the center of the BIG image. Then you can create the variables scrollX and scroll y, and put this script in every sprite:




<forever>
<go to x sad  scrollX )y sad  ScrollY
<end>


Joren


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#24 2007-12-17 16:46:00

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Scrolling Background - Help.

Thats the method I used in my scrolling landscape project - it makes it possible to rotate the "map" instead of the vehicle, so to speak...


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#25 2007-12-17 19:15:51

supercooldamian
Scratcher
Registered: 2007-12-16
Posts: 9

Re: Scrolling Background - Help.

supercooldamian wrote:

messd002 wrote:

Basically I have no clue on how to make scrolling backgrounds and any tutorial/advice/info on how to do it would be very appreciated. Please don't post a link to a project which contains scrolling because even if I do download it I can't make head nor Tails of it. Any post explaining basically what is happening is sort of what I need.


Many Thanks.

give me a idea of background so I can have a cool background

I have something to tell you I am a a cool boy so if you want you can e mail me anytime   
I don`t care how much times or if you do it in one second. Is that cool with you?

Offline

 

Board footer