Flixel Forums

development => help => Topic started by: Everandever on Fri, May 2, 2014

Title: Player Controls - Button fails to register if pressed too fast
Post by: Everandever on Fri, May 2, 2014
            if (FlxG.keys.justPressed("A"))
         player.velocity.x = -player.maxVelocity.x * 0;
         
            if (FlxG.keys.D)
         player.velocity.x = player.maxVelocity.x * 0.5;

If you press D, the player continuously moves to the right. If you press A, you're instantly at a fixed negative speed (maxvelocity.x is -25 here).

The problem is, if you're holding D, and then let go of D and press A too fast, it sometimes fails to register A, and you have to press it again. That's very bad for the purposes of this game.

If I trace it, there's always 2 D's after the last A whenever it doesn't work. So the problem is clear, the 2 D's overwrite the A before it can even happen. Now I just need a way to fix this.

Any help would be appreciated!

Title: Re: Player Controls - Button fails to register if pressed too fast
Post by: Everandever on Fri, May 2, 2014
Well, I guess I gotta apologize for this thread, I've already solved it. Albeit a little clumsy, I imagine:

//Player Controls
            if (FlxG.keys.A) // if you press A
            {
               if (FlxG.keys.D) // and D
               {
                  player.velocity.x = -25; // you will "stand still"
               }
               player.velocity.x = -25; // if you only press A you will also stand still
            }
         
            if (FlxG.keys.D) // if you press D
            {
         player.velocity.x = player.maxVelocity.x * 0.5; // you will move to the right
            }

cheers.
Title: Re: Player Controls - Button fails to register if pressed too fast
Post by: PRIZZA on Wed, May 14, 2014
What about just something like:
 
Code: [Select]
if (FlxG.keys.justPressed("A"))
         player.velocity.x = -player.maxVelocity.x * 0;
else if (FlxG.keys.D)
         player.velocity.x = player.maxVelocity.x * 0.5;

Or vice-versa. Would that be a feasible option?