Skip to content

Instantly share code, notes, and snippets.

/Main.hx Secret

Created March 29, 2016 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/481756e265bbbcf434ef9a8770d93050 to your computer and use it in GitHub Desktop.
Save anonymous/481756e265bbbcf434ef9a8770d93050 to your computer and use it in GitHub Desktop.
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