-
-
Save anonymous/481756e265bbbcf434ef9a8770d93050 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 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