Created
November 2, 2016 15:16
-
-
Save DleanJeans/97e8d94f44065ebf21d56f36e0842274 to your computer and use it in GitHub Desktop.
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 flixel.FlxG; | |
import flixel.FlxSprite; | |
import flixel.FlxState; | |
import flixel.math.FlxPoint; | |
class PlayState extends FlxState { | |
public static inline var SPEED = 1000; | |
public var sprite:FlxSprite; | |
public var switchFramerate:Bool = true; | |
override public function create() { | |
sprite = new FlxSprite(); | |
sprite.makeGraphic(50, 50); | |
sprite.screenCenter(); | |
sprite.maxVelocity.set(100, 100); | |
add(sprite); | |
FlxG.drawFramerate = 10; | |
FlxG.watch.add(this, "switchFramerate"); | |
FlxG.watch.add(FlxG, "fixedTimestep"); | |
FlxG.watch.add(FlxG, "elapsed"); | |
FlxG.watch.add(FlxG, "drawFramerate"); | |
FlxG.watch.add(sprite, "x", "x"); | |
FlxG.watch.add(sprite, "y", "y"); | |
} | |
override public function update(elapsed:Float) { | |
super.update(elapsed); | |
if (FlxG.keys.justPressed.SPACE) | |
FlxG.fixedTimestep = !FlxG.fixedTimestep; | |
if (FlxG.keys.justPressed.ENTER) { | |
switchFramerate = !switchFramerate; | |
if (!switchFramerate) | |
FlxG.drawFramerate = 60; | |
} | |
if (FlxG.keys.pressed.A) | |
sprite.velocity.x = -SPEED; | |
if (FlxG.keys.pressed.D) | |
sprite.velocity.x = SPEED; | |
if (FlxG.keys.pressed.W) | |
sprite.velocity.y = -SPEED; | |
if (FlxG.keys.pressed.S) | |
sprite.velocity.y = SPEED; | |
if (!FlxG.keys.anyPressed(["A", "D", "W", "S"])) | |
sprite.velocity.set(); | |
if (switchFramerate && sprite.velocity.equals(FlxPoint.weak())) { | |
FlxG.drawFramerate = 10; | |
} | |
else FlxG.drawFramerate = 60; | |
FlxG.watch.addQuick("updateFramerate", 1 / FlxG.elapsed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment