Created
February 10, 2014 20:41
-
-
Save joonjoonjoon/8923774 to your computer and use it in GitHub Desktop.
time-based solution for framerate drop
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
class GameClass extends FlxGame | |
{ | |
private var useCustomFpsCounter:Bool = false; | |
public function new() | |
{ | |
// Launch your game here | |
// INIT FRAME COUNTER | |
Lib.current.stage.addEventListener(Event.ENTER_FRAME, frameRateUpdate); | |
if (useCustomFpsCounter) | |
{ | |
framecountertext = new TextField(); | |
framecountertext.defaultTextFormat = new TextFormat(FlxAssets.FONT_DEBUGGER, 20, 0xbbbbbb, false, false, false, null, null, TextFormatAlign.LEFT ); | |
framecountertext.text = "60 - 60"; | |
framecountertext.x = Lib.current.stage.stageWidth/2 - framecountertext.textWidth /2; | |
framecountertext.y = 60; | |
framecountertext.width = 200; | |
Lib.current.stage.addChild(framecountertext); | |
} | |
} | |
public static var elapsedTime:Int; // use this anywhere to compensate for frame drops... | |
private var myticks:Int; | |
private var mytotal:Int; | |
private var timecounter:Int; | |
private var framecounter:Int; | |
private var framecountertext:TextField; | |
private function frameRateUpdate(?FlashEvent:Event):Void | |
{ | |
myticks = Lib.getTimer(); | |
elapsedTime = myticks - mytotal; | |
mytotal = myticks; | |
timecounter += elapsedTime; | |
framecounter++; | |
if (useCustomFpsCounter && timecounter > 1000) | |
{ | |
framecountertext.text = (framecounter -1) + " / " + 60; | |
framecounter = 0; | |
timecounter = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment