Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.