A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: double jump

  1. #1
    Member
    Join Date
    Sep 2004
    Location
    coventry,england
    Posts
    65

    double jump

    Hi,

    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.

    Key.as - http://flash.pastebin.com/m62e87afa

    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.

    http://flash.pastebin.com/m5f9bb319

    any help appreciated! i'm sure this should be pretty simple to fix, but i just can't work out how.

    J
    'flash is da bomb'

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    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.

  3. #3
    Member
    Join Date
    Sep 2004
    Location
    coventry,england
    Posts
    65
    hey,

    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.

    Code:
    		
    if (Key.isDown(Keyboard.UP) && jumps == 0)
    {
    	char.yAcc = -15;
    	jumps = 1;
    } 
               else if (Key.isDown(Keyboard.UP) && jumps == 1)
    {
    	char.yAcc = -15;
    	jumps = 2;
    }
    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?!
    Attached Files Attached Files
    'flash is da bomb'

  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    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.

    You could try changing the code to this:

    PHP Code:
    var isKeyHit:Boolean false;

    if (
    Key.isDown(Keyboard.UP) && jumps == 0)
    {
        
    char.yAcc = -15;
        
    jumps 1;
            
    i**** = true;

               else if (
    Key.isDown(Keyboard.UP) && jumps == && !isKeyHit)
    {
        
    char.yAcc = -15;
        
    jumps 2;
    }
    else
    {
    isKeyHit false;

    I think that should do it.

    You can also modify your Key class to have an is Key Hit function, but it is not necessary.

  5. #5
    Member
    Join Date
    Sep 2004
    Location
    coventry,england
    Posts
    65
    ah, thanks a lot

    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.
    'flash is da bomb'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center