PDA

View Full Version : Two Things



InsaneMonk
December 29th, 2003, 06:07 PM
Well, I actually have two things. First, I have an easy method for a jumping system in a flash game. It's a bit glitchy, but here it is:


onClipEvent(load) {
var fallness = 10; }
onClipEvent(enterFrame){
if (!this.hitTest(_root.ground) && !Key.isDown(Key.UP)) {
this._y += fallness;
}
if (Key.isDown(Key.UP)) {
gravity -= 1;
this._y -= gravity;
}
if (this.hitTest(_root.ground)) {
gravity = 10;
}
}
onClipEvent (keyUp) {
gravity = 10;
}

ok so there you can apply your own crap to it. And I have another thing to ask: how would you go by using a switch statement. ive been having trouble with them along with for.. in loops

InsaneMonk
December 30th, 2003, 12:28 PM
Sorry for double posting, but this thread has been up for a while, so could someone please reply. Thank-You for your help.

pom
December 30th, 2003, 12:51 PM
I'm not sure what your first question is, but you can find some information about the second here: http://www.kirupa.com/developer/actionscript/as_tricks.htm

pom :)

lunatic
December 30th, 2003, 12:59 PM
Same here with the first question but with the second you could use something like:

myVar = Key.getCode();

Then use myVar in a switch statement:


switch(myVar) {
case (37):
do some stuff;
break;
case (39):
do some other stuff;
break;
default:
do some default stuff;
break;
}


You can look up the numbers in the Flash reference for the key codes. Also check out Best of Senocular for excellent explanation of switch/case by clicking

here (http://www.kirupaforum.com/forums/showthread.php?s=&threadid=15407) :thumb:

InsaneMonk
January 1st, 2004, 04:27 PM
Thanx everyone! :} That helped alot. The first **question** was not actually a question. It was just open source. But I could turn it into a question. How could I make it less glitchy? The glitch is: when you jump, if you press UP again while you're in mid-air, you'll just jump agian. I tried creating a variable to have a ceratain value when you are jumping and when you are not. Then I made the if statement check if "jumping" was "true" but that just made more errors. Couold someone help me out?