### Author Topic: Player Controls - Button fails to register if pressed too fast  (Read 1382 times)

#### Everandever

• Member
• Posts: 10
• Karma: +0/-0
##### Player Controls - Button fails to register if pressed too fast
« 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!

« Last Edit: Fri, May 2, 2014 by Everandever »

#### Everandever

• Member
• Posts: 10
• Karma: +0/-0
##### Re: Player Controls - Button fails to register if pressed too fast
« Reply #1 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.

#### PRIZZA

• Member
• Posts: 24
• Karma: +0/-0
##### Re: Player Controls - Button fails to register if pressed too fast
« Reply #2 on: Wed, May 14, 2014 »