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

#1 2011-05-18 18:36:56

Yo-ma
Scratcher
Registered: 2007-12-15
Posts: 6

A few things I've never figured out...

1. How does one make other sprites move (say back and forth) in a scrolling game?
2. Is there anyway to prevent the running animations from overlapping?
for instance if I did:
when flag clicked, forever: if right arrow key is pressed-switch to costume 1_wait .1 secs_ switch to costume 2_wait.1 secs etc.

but also: when flag clicked, forever: if up arrow key is pressed-switch to costume 4_wait .1 secs_ switch to costume 5_wait.1 secs etc.

but when you're pressing the right arrow key, and press up arrow key within the time it takes for the run animation to take place, and the run animation is being played while jumping then how do you stop it...?!

Offline

 

#2 2011-05-18 21:08:22

estorken
Scratcher
Registered: 2010-04-01
Posts: 41

Re: A few things I've never figured out...

OK, i'm not famous (or even slightly popular) but i know what i'm talking about.
brace yourself, this will take a while.

question #1
you will need a variable called scrollx (or whatever you want, that is just a recommendation). you then put this script into all sprites that you want to scroll:

when green flag clicked
forever (or repeat until you're dead, up to you)
{
     set x to scrollx (you will need to add a certain number to get them to go to the right                    spot, without knowing where you want them i can't tell you that number)
}

if you want them to move back and forth, make another variable called x. this one will be a local variable (for this sprite only)
then add that variable to the x position script.
(set x to scrollx + x + whatever you want)





for this entire thing to work, you must make this change to you movement scripts. instead of changing your x position, change the scrollx variable (by a negative to move right, and positive to move left. same thing goes for the local variable)

this can also be used for the background sprites
here is a link to a scrolling tutorial

http://scratch.mit.edu/projects/04lukeb/77404










question #2. this one is almost as complex. there are many ways to do this. i'll tell you my favourite.

combine the forevers and create a variable called jump. make this local unless you will need it for something else in other sprites

when green flag pressed
forever
{
     if (right arrow pressed)
     {
         change x by 5 (or whatever)
         if (jump = 0)
         {
                 switch to costume 1
         }
         wait.1 secs
         {
                 switch to costume 2
         }
     }
     else (left arrow pressed)
     {
          change x by -5
         if (jump = 0)
         {
                 switch to costume 1
         }
         wait.1 secs
         {
                 switch to costume 2
         }
     }
}

then make a separate script of

when green flag clicked
forever
{
     if(up arrow clicked)
     {
         if (touching ground, don't use jump=0 because if you walk off a ledge jump = 0    but you aren't touching ground)
         {
                 set jump to 1
                 set y velocity to 8 (or whatev)
                 switch to costume 4
                 wait .1 sec
                 switch to costume 5
         }
}










i know this is a lot, but it works (i think...)
if there is a simpler way i either can't remember it right now, or i don't know it.

sorry i don't have a tutorial for this one, even though it is as hard...

good luck with scratch, i hope this isn't too intimidating. these are advanced... what'st he word... thingimibobbers. if you take my advice, please view and comment on my projects. thanks.

i'll explain how this works if you want


http://i56.tinypic.com/esqpma.gif

Offline

 

Board footer