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

#51 2008-04-11 16:35:49

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

Re: Scrolling Background - Help.

Looby wrote:

WOAH!!!! ARCHMAGE! THATS REALLY COMPLICATED!
There is a really simple way of doing it, even with multiple sprites.

It's really not complex. Memorizing 5 lines of code isn't hard.


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

 

#52 2008-04-12 13:04:30

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Scrolling Background - Help.

archmage wrote:

Looby wrote:

WOAH!!!! ARCHMAGE! THATS REALLY COMPLICATED!
There is a really simple way of doing it, even with multiple sprites.

It's really not complex. Memorizing 5 lines of code isn't hard.

I agree. I memorized that, the code you can use instead of the distance to block, and I memorized how to immitate the move block. Well I didn't totally remember archmage's thing but I'm close.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#53 2008-04-18 15:00:46

xjediboy11
Scratcher
Registered: 2008-03-01
Posts: 5

Re: Scrolling Background - Help.

Hey Archmage thx a lot for the help. I put up a question in the forums about scrolling, and all i got was allot of "go to this" or "view this" or "download this." THANK YOU FOR YOUR HELP!
______________________________
           Ninja Saying

For every 100 men you send to us
ten should not be here,
eighty are nothing but targets,
nine are real fighters,
but one is a true WARRIOR
and will bring the rest back.

Offline

 

#54 2008-04-19 09:53:19

lilhd
Scratcher
Registered: 2007-12-03
Posts: 26

Re: Scrolling Background - Help.

the mouse pointer one is not working for me at all.

Offline

 

#55 2008-04-19 10:24:10

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Scrolling Background - Help.

I used your tutorial, but found myself how to do it unlimited. For example in my Metal Slug game: [blocks]<when green flag clicked>[/blocks]
                [blocks]<forever if><{ scrollx<(  <<>  )> }>-475[/blocks]
                [blocks]<set{ scrollx }to( 0[/blocks]


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#56 2008-04-19 10:34:44

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

Re: Scrolling Background - Help.

Bluestribute wrote:

I used your tutorial, but found myself how to do it unlimited. For example in my Metal Slug game: [blocks]<when green flag clicked>[/blocks]
                [blocks]<forever if><{ scrollx<(  <<>  )> }>-475[/blocks]
                [blocks]<set{ scrollx }to( 0[/blocks]

Good for you. It's great that you were able to come up with your code codes to use for scrolling purposes  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

 

#57 2008-04-19 18:21:47

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Scrolling Background - Help.

Ya, but I memorized your code.


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#58 2008-05-26 20:27:07

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

Re: Scrolling Background - Help.

I just fixed a typographical error in the movement script for the second scrolling

method. I forgot to put a <end> in the second if block.

Thanks to paddle2see for letting me know about it  smile

Last edited by archmage (2008-05-26 20:31:53)


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

 

#59 2008-06-15 01:07:45

mandarkey
Scratcher
Registered: 2008-06-15
Posts: 5

Re: Scrolling Background - Help.

Why not try and use the project how to scroll and download it?  big_smile   [blocks]<y position>[blocks]

Offline

 

#60 2008-06-15 01:09:25

mandarkey
Scratcher
Registered: 2008-06-15
Posts: 5

Re: Scrolling Background - Help.

sorry about the y position block in the way of " Why not try and" part of it.  lol

Offline

 

#61 2008-06-15 01:31:58

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

Re: Scrolling Background - Help.

mandarkey wrote:

Why not try and use the project how to scroll and download it?  big_smile   [blocks]<y position>[blocks]

The tutorial in the forum post uses the same scripts. I also have a few scrolling demos people can download.


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

 

#62 2008-06-17 20:11:09

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: Scrolling Background - Help.

Hey, archmage, can you tell me how to do this for scrolling?

I want the to be one person in the middle of the screen, multi directional scrollong, like that plane thing of yours. Anyway, when the person when the last terrain is in its view, for it to stop scrolling in that direction and instead have the character be able to walk up the the wall without it scrolling in that direction. So you can't see the backround in a way.
Thanks for the help!

Offline

 

#63 2008-06-17 20:14:12

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Scrolling Background - Help.

Bobby500 wrote:

Hey, archmage, can you tell me how to do this for scrolling?

I want the to be one person in the middle of the screen, multi directional scrollong, like that plane thing of yours. Anyway, when the person when the last terrain is in its view, for it to stop scrolling in that direction and instead have the character be able to walk up the the wall without it scrolling in that direction. So you can't see the backround in a way.
Thanks for the help!

Personally, I would use something like this (note you need very simple backgrounds) http://scratch.mit.edu/forums/viewtopic.php?id=5919 because it dwals with littler numbers. Otherwise, you would have something liek if scroll is less than something your guy doesn't move and scrolls, otherwise he moves


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#64 2008-06-17 20:19:31

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

Re: Scrolling Background - Help.

Bobby500 wrote:

Hey, archmage, can you tell me how to do this for scrolling?

I want the to be one person in the middle of the screen, multi directional scrollong, like that plane thing of yours. Anyway, when the person when the last terrain is in its view, for it to stop scrolling in that direction and instead have the character be able to walk up the the wall without it scrolling in that direction. So you can't see the backround in a way.
Thanks for the help!

If you don't want to scroll past a certain point set the scrollX variable to a lower number when it goes over the limit

like this

if (scrollX> 100)
set scrollX to 100

This way scrollX will never be greater than 100.


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

 

#65 2008-06-17 20:26:22

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: Scrolling Background - Help.

I know this sounds easy to you and I appreciate the help but I am working with and extremly irregular map. I mean it is like

........................
....                   .....
....              .........
                        ......
........................
....                    ......
....

Is there any way so that if it sees the backround or something it will stop scrolling in the direction that the backround is showing?

Last edited by Bobby500 (2008-06-17 20:27:19)

Offline

 

#66 2008-06-17 20:38:16

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

Re: Scrolling Background - Help.

Bobby500 wrote:

I know this sounds easy to you and I appreciate the help but I am working with and extremly irregular map. I mean it is like

........................
....                   .....
....              .........
                        ......
........................
....                    ......
....

Is there any way so that if it sees the backround or something it will stop scrolling in the direction that the backround is showing?

So basically you don't want the scrollX variable to go past a certain value? Do you want to put a limit on how far you can scroll?


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

 

#67 2008-06-18 06:26:21

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: Scrolling Background - Help.

Yeah, pretty much. I just want it to always see the terrain sprites and not the backround.

Offline

 

#68 2008-06-18 06:28:06

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Scrolling Background - Help.

My Wilsons Intro Game uses something like that, but my velocity is a good example. Just switch the setting to 0 and what not to scrollX. I still think Wilson Intro is best way


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#69 2008-06-18 06:56:31

Goldfish01
Scratcher
Registered: 2008-05-08
Posts: 36

Re: Scrolling Background - Help.

Thanks I was feeling like like a total ninny not knowing how to scroll


Improvement is dissasembling something and not putting it back together properly.

Offline

 

#70 2008-06-18 08:44:41

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: Scrolling Background - Help.

Never mind, I found a way to do it without haveing to scroll to much. Thanks for all of your guys help!  smile

Offline

 

#71 2008-06-28 08:59:00

Winner
Scratcher
Registered: 2008-03-10
Posts: 100+

Re: Scrolling Background - Help.

How do I jump?


Jesus is the true Winner! I'm leaving Scratch.
Find me on theinterwebs! ~TDWfan.

Offline

 

#72 2008-06-28 12:41:01

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Scrolling Background - Help.

Here is a project I created a while ago. It allows you to design your own scroller. Just click and drag the dots, press the button, and add in a player sprite. By the way, the pen color is not exactly black, but it is close. This scroller is being dynamically created through use of the pen. http://scratch.mit.edu/projects/Cyclone103/155940 all lines must be either horizontal or vertical. I hope this helps! I created another version that already has the player sprite in it, for those of you who are interested.


All your base are belong to us

Offline

 

#73 2008-06-30 15:30:05

Zelda123
Scratcher
Registered: 2007-11-21
Posts: 1000+

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

With the help of this and studying the code of your perfect sidescrolling engine, I was able to make a guide partly about it.
http://scratch.mit.edu/projects/Zelda123/200396

Offline

 

#74 2008-07-15 11:35:26

3210werdnahcaz
Scratcher
Registered: 2008-07-15
Posts: 2

Re: Scrolling Background - Help.

my scrolling still glitches up using the 2nd method!

Offline

 

#75 2008-07-15 11:36:37

zachandrew0123
Scratcher
Registered: 2008-02-28
Posts: 500+

Re: Scrolling Background - Help.

and zelda123's versoon as well

Offline

 

Board footer