Created
February 28, 2011 15:46
-
-
Save goshki/847489 to your computer and use it in GitHub Desktop.
Check for how long the given key has been held in FlashPunk mitigating the key-repeat under Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.utils.getTimer; | |
import net.flashpunk.*; | |
import net.flashpunk.utils.*; | |
/** | |
* <p> | |
* The reason to use such test is that under Linux holding a key triggers a key-repeat functionality after | |
* a moment and so, key-press events are generated. Therefore the Input.pressed() method will periodically | |
* report true even though the player just holds the key. Such behaviour is not noticeable under Windows | |
* (player has to release the button and press it again to generate a key-press event). | |
* | |
* <p> | |
* The same problem exists in Flixel with the FlxG.justPressed() method. | |
*/ | |
public class FlashPunkKeyholdTest extends Engine { | |
public var spaceWasPressed:Boolean = false; | |
public var spacePressTime:int = 0; | |
public function Main() { | |
super( 640, 480, 60, false ); | |
} | |
override public function update():void { | |
super.update(); | |
if ( Input.check( Key.SPACE ) ) { | |
if ( !spaceWasPressed ) { | |
spaceWasPressed = true; | |
spacePressTime = getTimer(); | |
} | |
} | |
else { | |
if ( spaceWasPressed ) { | |
trace( "SPACE press time: " + ( getTimer() - spacePressTime ) ); | |
spaceWasPressed = false; | |
spacePressTime = 0; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment