Skip to content

Instantly share code, notes, and snippets.

/Main.hx Secret

Created Mar 29, 2016
Embed
What would you like to do?
package;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.Lib;
import openfl.Assets;
class Main extends Sprite {
private var image: Bitmap;
private var previousTimeMilliseconds = 0;
private var maxDeltaTimeSeconds = 1.0 / 30.0;
public function new () {
super();
var imageBitmapData = Assets.getBitmapData("img/EasyToUse.png");
image = new Bitmap(imageBitmapData);
addChild(image);
addEventListener (Event.ENTER_FRAME, this_onEnterFrame);
}
private function this_onEnterFrame (event:Event):Void {
var currentTimeMilliseconds = Lib.getTimer();
var deltaTimeMilliseconds = (currentTimeMilliseconds -
previousTimeMilliseconds);
var deltaTimeSeconds = deltaTimeMilliseconds / 1000;
if (deltaTimeSeconds > maxDeltaTimeSeconds) {
deltaTimeSeconds = maxDeltaTimeSeconds;
}
var speedPixelsPerSecond = 40.0;
var dx = speedPixelsPerSecond * deltaTimeSeconds;
image.x += dx;
previousTimeMilliseconds = currentTimeMilliseconds;
trace(deltaTimeSeconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment