i'm making a platform game in flash, but not a tile based one. I've got jumping sorted, and general control of a character. i'm trying to put a double jump in, and it's proving difficult! If anyone can advise me how to do this i'd be really grateful! i've included links to pastebin with my code. it's in AS3, so i've used a custom Keyboard class, (called Key.as) to check for key presses.
The code used to make the character jump i've condensed into this next pastebin, think it includes everything that's relevant to jumping, at least the way i've currently done it. it's got one section from my main game loop (inside the .fla) and one section from my character class. i've marked them in the pastebin.
It seems from the code that the player can only do a double jump exactly when the acceleration is 0. What you probably want is a range, say if the acceleration is between -1 and 1, allow a double jump.
i'm not sure that the problem is to do with my y acceleration value, it seems to be an issue with the jump key being held down for too long (even if 'too long' is 1/2).
i've attached the swf file, to give you an idea of the issue. i tried this code, which seems to me should work. it's based on a jumps variable, which is 0 when yAcc = 0, 1 when you do your first jump, and 2 when you've pressed the jump key twice in the air.
but as you see from the swf, the value of 'jumps' (the 4th number displayed) when you press UP to jump goes immediately to 2. if you manage to tap the jump button *REALLY* quickly, it'll just show a 1, and then you can press again to do the double jump.
so the problem seems to be the way the isDown thing is working in my Key.as. I'm sure i didnt have this problem in AS2...
thanks for your help
ps, the swf's in a zip file.. why doesnt flash kit let you upload a swf?!
Just from looking at the code, once you press the key, jump is set to 1. So if you hold the jump button for two frames (not very much time at all, as you described), it will do the second jump immediately following the first.
So what you are really looking for here is the idea of key hit now key down.
i ended up solving it, with the help of the mighty iopred, and looking at what you've said it was pretty similar.
however i'm interested if you've got a suggestion as to how i'd put a keyHit method into my keyclass. i thought about this (could be useful later) but i couldnt figure out how i'd do it.