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

#1 2008-11-03 21:11:07

tharvoil
Scratcher
Registered: 2008-10-24
Posts: 24

Help w/ scrolling

Okay I'm working on a scrolling game of sorts, and have never done any scrollers before, in fact im prettty enw to scratch. Thing is when i reasearched scrollers it seems like i can eaither mvoe the sprite OR the background, and as I'm trying to make a Zelda-themed game neitehr works real well, or rather has limits. I've heard rumors of a way to make it so the main sprite(Link in my case) can move from like 1 half to the otehr without moving teh background but when he gets close enough to the edge of the screen, the background starts scrolling along with him. Anybody know where I could get some help for that?

Offline

 

#2 2008-11-03 21:53:39

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

Re: Help w/ scrolling

Here's what I think the code for that should look like. I assume you want to scroll like in the original mario game.

if (left key pressed)
move sprite to the left
if (right key pressed)
if (sprite's X position>0)
scroll to the right
else
move sprite to the right

That should cover all of your moving & scrolling needs.

Last edited by archmage (2008-11-03 21:54:28)


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 2008-11-03 22:20:43

bart9032
Scratcher
Registered: 2008-06-16
Posts: 100+

Re: Help w/ scrolling

I think archmage means this:

Have a variable called scrollx and one called sprite<(  <>>  )>
Then do this script
[blocks]<when green flag clicked>
<forever>
<if><key[ left arrow ]pressed?>
<move(-10  )steps>
<end>
<if><key[ right arrow ]pressed?>
<if><(<{sprite  }>  <>> 0 )>
<change{ scrollx }by( -1
<else>
<move( 10 )steps>
<end>
<end>
<end>[/blocks]

For Sprite variable we do this.
[blocks]<when green flag clicked>
<forever>
<set{ sprite }to( <x position>
<end>

Now for jumping we can do this. Have a variable called yVelocity.
This is the script you can put in.
<when green flag clicked>
<set{ yVelocity }to( 0
<forever>
<if><touching[ ground
<set{ yVelocity }to( 0 )
<else>
<change{ yVelocity }by( -1
<change y by( <{ yVelocity }>
<end>
<end>


Hi, my name is Bartholomew JoJo 'Bart' Simpson. Nice to meet you,
Actually, no I am not Bart Simpson. I am bart9032  cool

Offline

 

#4 2008-11-03 22:22:07

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

Re: Help w/ scrolling

yea, my RPG demo has that type of scrolling in X as well as Y if you want to have a look

Offline

 

#5 2008-11-04 09:40:04

tharvoil
Scratcher
Registered: 2008-10-24
Posts: 24

Re: Help w/ scrolling

Thanks alot, I'm gonna try putting those codes in now and see if itll do what it should.

Offline

 

Board footer