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

#151 2009-04-19 19:17:14

tylerscheller
Scratcher
Registered: 2009-03-22
Posts: 9

Re: Scrolling Background - Help.

<{ScrollX}>

Offline

 

#152 2009-04-19 19:28:12

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

Re: Scrolling Background - Help.

What about it?


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

 

#153 2009-04-25 19:44:24

Talbenari1
Scratcher
Registered: 2008-06-20
Posts: 1

Re: Scrolling Background - Help.

<change{  }by( <turn cw(  )degrees><move(  )steps>

Offline

 

#154 2009-04-25 20:03:01

DawnLight
Scratcher
Registered: 2009-04-25
Posts: 500+

Re: Scrolling Background - Help.

Scrolling backgrounds is a advance topic so I think this should be moved to "Advance Topics".This will fit nicely as a sticky there!
Also, I really suggest archmage's scrolling background projects.They are great for tutorials!

Hope that Helps!  big_smile

Offline

 

#155 2009-04-25 20:05:40

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

Re: Scrolling Background - Help.

Talbenari1 wrote:

<change{  }by( <turn cw(  )degrees><move(  )steps>

pleasse do not spam


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

 

#156 2009-04-25 20:20:42

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

Re: Scrolling Background - Help.

DawnLight wrote:

Scrolling backgrounds is a advance topic so I think this should be moved to "Advance Topics".This will fit nicely as a sticky there!
Also, I really suggest archmage's scrolling background projects.They are great for tutorials!

Hope that Helps!  big_smile

Scrolling is actually pretty simple and many people ask about it in the all about scratch forum.

I think it fits well here.


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

 

#157 2009-04-25 20:35:30

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

Re: Scrolling Background - Help.

archmage wrote:

DawnLight wrote:

Scrolling backgrounds is a advance topic so I think this should be moved to "Advance Topics".This will fit nicely as a sticky there!
Also, I really suggest archmage's scrolling background projects.They are great for tutorials!

Hope that Helps!  big_smile

Scrolling is actually pretty simple and many people ask about it in the all about scratch forum.

I think it fits well here.

yah


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

 

#158 2009-05-06 11:35:20

pokemon_master12
Scratcher
Registered: 2008-09-26
Posts: 100+

Re: Scrolling Background - Help.

See archmage's tutorial on scrolling backgrounds. It really helped me a lot.  smile


My Dragon Egg! http://dragcave.net/image/5YUA.gif
Visit my blog: http://freyasworld.wordpress.com/

Offline

 

#159 2009-05-06 14:34:04

mouchc84
Scratcher
Registered: 2009-04-29
Posts: 1

Re: Scrolling Background - Help.

i did exactly what he was saying in the 1st section but it wont scroll. the terrain sprites (blue solid blocks running across the background which is a city)  just sit behind each other and when you get to the edge it does nothing.

Offline

 

#160 2009-05-06 14:38:18

ScratchX
Scratcher
Registered: 2009-05-05
Posts: 1000+

Re: Scrolling Background - Help.

i love this!


Happy New Year!
http://i45.tinypic.com/1nyasi.pnghttp://i50.tinypic.com/219pez8.pnghttp://i49.tinypic.com/e5s4zr.pnghttp://i48.tinypic.com/23l18hf.jpghttp://i49.tinypic.com/66zymu.png

Offline

 

#161 2009-05-06 15:49:04

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

Re: Scrolling Background - Help.

mouchc84 wrote:

i did exactly what he was saying in the 1st section but it wont scroll. the terrain sprites (blue solid blocks running across the background which is a city)  just sit behind each other and when you get to the edge it does nothing.

That means you didn't change the number on each sprite. Read my instructions more carefully.


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

 

#162 2009-05-06 18:02:33

ScratchX
Scratcher
Registered: 2009-05-05
Posts: 1000+

Re: Scrolling Background - Help.

wow it works! wink


Happy New Year!
http://i45.tinypic.com/1nyasi.pnghttp://i50.tinypic.com/219pez8.pnghttp://i49.tinypic.com/e5s4zr.pnghttp://i48.tinypic.com/23l18hf.jpghttp://i49.tinypic.com/66zymu.png

Offline

 

#163 2009-05-06 19:41:39

DawnLight
Scratcher
Registered: 2009-04-25
Posts: 500+

Re: Scrolling Background - Help.

ScratchX wrote:

wow it works! wink

What scrolling?

Offline

 

#164 2009-05-06 20:11:42

ScratchX
Scratcher
Registered: 2009-05-05
Posts: 1000+

Re: Scrolling Background - Help.

yes because i liked the second method


Happy New Year!
http://i45.tinypic.com/1nyasi.pnghttp://i50.tinypic.com/219pez8.pnghttp://i49.tinypic.com/e5s4zr.pnghttp://i48.tinypic.com/23l18hf.jpghttp://i49.tinypic.com/66zymu.png

Offline

 

#165 2009-05-16 22:53:19

Sonor44
Scratcher
Registered: 2008-12-27
Posts: 5

Re: Scrolling Background - Help.

I can make my character scroll up, left, right . . . but having it "fall" down is a big problem. I tried lot's of different things to get it to "fall" down below to awaiting terrains, but it just won't. Any ideas would be very helpful.

Joey

Offline

 

#166 2009-05-16 22:56:47

fruit
Scratcher
Registered: 2009-04-24
Posts: 1000+

Re: Scrolling Background - Help.

Sonor44 wrote:

I can make my character scroll up, left, right . . . but having it "fall" down is a big problem. I tried lot's of different things to get it to "fall" down below to awaiting terrains, but it just won't. Any ideas would be very helpful.

Joey

Hi, try making this:

<when green flag clicked>
<forever>
<if><<  <not> <key[  ]pressed?> >> (do NOT * PRESSED for each key you used)

<forever>
<change y by( -10
<end>
<end>
<end>

Last edited by fruit (2009-05-16 22:59:38)


@savi3000 | hcsmp.com

Offline

 

#167 2009-06-24 22:35:54

celloguy123
Scratcher
Registered: 2009-01-15
Posts: 100+

Re: Scrolling Background - Help.

THANK YOU ARCHMAGE!!! i havent created a scrolling project yet but i will!!!  Thanks again!!!


http://internetometer.com/image/33068.png

Offline

 

#168 2009-08-09 23:11:38

onpaperwings
Scratcher
Registered: 2007-10-05
Posts: 6

Re: Scrolling Background - Help.

Archmage, can you explain how in the scrolling script you can use 480 times 1 because 1 is what the sprite name ends with please?

I don't understand how that works or how you figured that out.


Jacob: Programmer/Musician
http://imgur.com/XBSry.png

Offline

 

#169 2009-08-09 23:38:53

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

Re: Scrolling Background - Help.

terrian1 has the script 480*1 and appears first, terrain2 has the script 480*2 and appears second


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

 

#170 2009-08-16 01:26:44

Bass_Player_TYSA
Scratcher
Registered: 2008-01-30
Posts: 9

Re: Scrolling Background - Help.

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

I really love your system Archmage. But I do have a problem with the costumes flashing at slower "velocities". Is there anything I can do about it?
big_smile

Offline

 

#171 2009-09-17 16:01:08

floatingmagictree
Scratcher
Registered: 2008-10-21
Posts: 1000+

Re: Scrolling Background - Help.

Capital V 0.0 is a great example of a scrolling game.

Offline

 

#172 2009-12-10 23:43:11

fishboy187
Scratcher
Registered: 2009-11-20
Posts: 13

Re: Scrolling Background - Help.

So how do you make the scrolling stop when it gets to the end of the terrain sprites? would it be like this? [blocks] <when green flag clicked> <forever if><( <x position> <>>-5  )> [/blocks] or am i just insane?

Offline

 

#173 2009-12-11 17:17:09

ikuehne
Scratcher
Registered: 2009-04-15
Posts: 15

Re: Scrolling Background - Help.

Here's a scrolling project--I basically made it for remixes. I made it (accidentally at first) so that it seems like it scrolls infinitely. I would appreciate a suggestion about how to make the movement of other sprites relative to the player-controlled one more realistic.
http://scratch.mit.edu/projects/ikuehne/798690

Offline

 

#174 2009-12-11 17:22:53

RHY3756547
Scratcher
Registered: 2009-08-15
Posts: 1000+

Re: Scrolling Background - Help.

I have a better solution to this that is used in real games and works with Zooms. ScrollX and Y aren't the way you're meant to do it with real games, but instead using variables called CameraX and CameraY, and TrueX and TrueY in all sprites (also zoom if you want). Basically, you just set the Xpos to (TrueX-CameraX)*Zoom and the Ypos to (TrueY-CameraY)*Zoom.

Offline

 

#175 2009-12-11 17:29:37

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

Re: Scrolling Background - Help.

It doesn't really matter what the variables are called. But you could apply your methods no matter what the variables are called. I named the variables scrollX and scrollY because it gives people an idea of the purpose of the variables.


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

 

Board footer