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

#101 2008-09-21 12:44:11

agleplop
Scratcher
Registered: 2008-09-10
Posts: 2

Re: Scrolling Background - Help.

brilliant help

Offline

 

#102 2008-10-01 15:27:37

Marine43753
Scratcher
Registered: 2008-08-25
Posts: 16

Re: Scrolling Background - Help.

check this out:  http://scratch.mit.edu/projects/Marine43753/276484 scrolling game!



have fun!  smile

Offline

 

#103 2008-10-03 17:41:15

madscientist113
Scratcher
Registered: 2008-03-20
Posts: 4

Re: Scrolling Background - Help.

awesome!!!! i can use this, right?

Offline

 

#104 2008-10-18 11:52:25

nkc
Scratcher
Registered: 2008-09-05
Posts: 3

Re: Scrolling Background - Help.

I need help scrolling up and down can someone show me???

Offline

 

#105 2008-10-18 12:00:38

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

Re: Scrolling Background - Help.

nkc wrote:

I need help scrolling up and down can someone show me???

Do everything in the tutorial again, except replace x with y and replace 480 with 360.


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

 

#106 2008-10-28 09:08:17

registeel
Scratcher
Registered: 2008-04-27
Posts: 500+

Re: Scrolling Background - Help.

Take a look at my project "Timmy's scrolling adventure" to find out how to scroll.

Offline

 

#107 2008-11-14 20:59:21

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Scrolling Background - Help.

I need help. I have the same scripts as yours, Identical and yet the scrolling skips forward every time it changes a terrain number. I am using the second version. Any ideas?

Offline

 

#108 2008-11-14 21:40:36

WolfDemon
Scratcher
Registered: 2008-10-07
Posts: 32

Re: Scrolling Background - Help.

Thank you archmage!!!

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


Random Acts of Kindness Does a Person Good  smile

Offline

 

#109 2008-11-14 22:29:15

afurlong
Scratcher
Registered: 2008-11-14
Posts: 6

Re: Scrolling Background - Help.

I'm a beginner at 3 games not yet posted and I entered a school contest with my friends. The prize is that you can yell at them if they do something wrong. I am making a Mario Game. But I have a really weird but fun drawing game. Here it is [blocks]<when green flag clicked><forever><go to[ mouse pointer><pen down><change pen color by( 10<change pen size by( 10<change pen color by( 10<change pen size by( -10[/blocks]

[blocks]<when[space]key pressed><clear>[/blocks]

Offline

 

#110 2008-11-14 22:32:16

afurlong
Scratcher
Registered: 2008-11-14
Posts: 6

Re: Scrolling Background - Help.

Let me rephrase that

[blocks]<when green flag clicked><pen down><forever><go to[mouse pointer <change pen color by( 10<change pen size by( 10<change pen color by( 10<change pen size by( -10[/blocks]

[blocks]<when[ space ]key pressed><clear>

Offline

 

#111 2008-11-14 23:05:33

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

Re: Scrolling Background - Help.

TheSaint wrote:

I need help. I have the same scripts as yours, Identical and yet the scrolling skips forward every time it changes a terrain number. I am using the second version. Any ideas?

If the coding is the same it should act the same. Check your costumes and make sure its like the example I posted.


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

 

#112 2008-11-15 06:57:18

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Scrolling Background - Help.

Okay, I inserted the coding into my project. Works great but that wasn't the problem. I didn't realize that I needed all the costumes in both sprites. Now I have a different problem. THe scrolling works great but the variables that I imported in...They don't show there values. As I scroll around, They all say zero. It is odd. Might be a glitch, I don't know. I will try to replace them or somthing.

Offline

 

#113 2008-11-15 07:57:57

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Scrolling Background - Help.

I got it to work now. Thanks!

Offline

 

#114 2008-11-29 10:38:44

takide
Scratcher
Registered: 2008-11-18
Posts: 14

Re: Scrolling Background - Help.

<mouse y><mouse y><mouse y><mouse y><mouse y><mouse y><mouse y><mouse y><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits><play sound[  ]and waits>

Offline

 

#115 2008-12-05 03:13:12

arne0108
Scratcher
Registered: 2008-11-11
Posts: 32

Re: Scrolling Background - Help.

Some of my games are good

http://scratch.mit.edu/users/arne0108

Offline

 

#116 2009-01-02 22:27:09

726961
Scratcher
Registered: 2008-11-26
Posts: 100+

Re: Scrolling Background - Help.

try downloading a scrolling project and see how it works. I really can't help to much on this subject but I will try.


http://scratch.mit.edu/projects/726961/604658 play it now! or else...

Offline

 

#117 2009-01-05 03:15:15

prokohtu
Scratcher
Registered: 2008-06-19
Posts: 100+

Re: Scrolling Background - Help.

Many thanks to Archmage and his explanation about scrolling. I like scraching and the scrolling is very useful for me.

Thanks,
Prokhtu.


Scratch's most realistic F1 simulator
https://lh6.googleusercontent.com/-qIdF-SzbTzw/UU29tK-FYvI/AAAAAAAAAOs/vRFKr1Iwldc/s225/logo.jpg

Offline

 

#118 2009-01-05 13:43:39

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

Re: Scrolling Background - Help.

prokohtu wrote:

Many thanks to Archmage and his explanation about scrolling. I like scraching and the scrolling is very useful for me.

Thanks,
Prokhtu.

I am glad you found it helpful  smile


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

 

#119 2009-01-06 11:38:36

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

Re: Scrolling Background - Help.

You need to make the background into a sprite and add the same script as you would if you were making the sprite move using the arrow keys. Then it looks like the SPRITE is moving when actually the BACKGROUND is moving instead, to make a scrolling background.
Happy Scratch-ing!  smile


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

Offline

 

#120 2009-01-06 14:12:01

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

Re: Scrolling Background - Help.

pokemon_master12 wrote:

You need to make the background into a sprite and add the same script as you would if you were making the sprite move using the arrow keys. Then it looks like the SPRITE is moving when actually the BACKGROUND is moving instead, to make a scrolling background.
Happy Scratch-ing!  smile

What you typed confused me  sad

You talk as if the sprites and the background are 2 different things when the sprites ARE the background. Honestly, it isn't a very complex concept.


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

 

#121 2009-01-07 10:12:56

Lightnin
Scratch Team
Registered: 2008-11-03
Posts: 1000+

Re: Scrolling Background - Help.

Is it possible to copy markings made by the pen and then move them over a pixel or two in order to create a scrolling effect with markings?


Help Scratchers make the leap to 2.0!
http://img818.imageshack.us/img818/6844/transitionteam.jpg

Offline

 

#122 2009-01-07 15:55:59

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

Re: Scrolling Background - Help.

Lightnin wrote:

Is it possible to copy markings made by the pen and then move them over a pixel or two in order to create a scrolling effect with markings?

Yes, but it would go really really slow.


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

 

#123 2009-01-09 06:11:14

tcam
Scratcher
Registered: 2008-11-05
Posts: 8

Re: Scrolling Background - Help.

Not about topic but can you use a two-stroke motor on a billy cart?

Offline

 

#124 2009-01-09 18:52:56

harleycurnow
Scratcher
Registered: 2009-01-09
Posts: 24

Re: Scrolling Background - Help.

how do u bake a vehical drive along it

Offline

 

#125 2009-01-09 18:55:44

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

Re: Scrolling Background - Help.

Sorry, I don't know how to bake things.

But, if you want you could replace the costumes(perhaps with a car) on the example scrolling project that comes with scratch.


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