PDA

View Full Version : jumping +game!


dramarc
03-18-2002, 12:32 PM
Hi!
I'm working on a game and I have a problem that's reallay annoying me! I want my kick-ass Flash soldier to jump when I press a key: THe problem I have is that if the button is held down, the jump scrip just keeps going and going and my character starts flying away! (move out of the screen).
I what the jump-script only be executed when the charater is on the ground and not while airborne! I've tried different ideas with button scripts, booleans etc, but none of the work!

ANy suggestionS!

/anders

fatass
03-18-2002, 12:40 PM
You could try having a state attached to the man, i.e. manState = "walking"; for when he's walking or manState = "jumping" for when he's jumping.

Then when you call the jump function wrap an if around the code:

if (manState != "jumping") {
//do all your jumping stuff and add
manState = "jumping";
}

that way it will only be called once.

When he lands change the manState back to walking and off you go!

dramarc
03-18-2002, 12:46 PM
What do you mean by state? Like a label inside the movieclip (the character) One for walking and one frame for jumping including the jumpscript?

/anders

fatass
03-18-2002, 12:53 PM
I mean like a variable.

If you have 1 variable which controls the state of your man, you can make sure he only does 1 thing at a time, walking or jumping.

Did you get the script bit of the post?

I mean for the state to be a flag or switch forcing the jump script to only run once.

dramarc
03-18-2002, 04:37 PM
Hi agian!
I'm not really following your ideas and your script..
What will prohibit the jump action from beeing executed ?

best regards
/anders

fatass
03-18-2002, 04:43 PM
the if statement

if (manState != "jumping") {

//make the little blighter jump

manState = "jumping";

}

if the state switch (manState) is NOT equal to "jumping" then execute the jump code AND set the state switch to equal "jumping".
Therefore when your key press tries to run the jump code again, it gets to the if statement and says: OH, manState is "jumping", in that case I won't make him jump again, cos he already is.

Then when he lands set the switch back to "walking" or whatever, as long as its not "jumping" because otherwise, he will never jump again.

hope that helps.

Paul

dramarc
03-18-2002, 04:53 PM
Thanks! I'll try!

/anders

dramarc
03-19-2002, 10:23 AM
Hi again!
I can't get it to work!!
I've tried with booleans, but the problem remains..
I'll attach my no-good-piece-of crap script when I get home..

/anders