Hello folks,
I have this frame-based counter I use instead of the timer-class because everything in my game is frame-based. This counter ensures that everything runs fine even when used on old computers.
I would like to know if it makes sense to create a tenth-second-frame-based-counter (or even a twentieth-second-frame-based counter). Basically it would be nearly the same counter like the one below except for the fact that the framesPerSecond-variable is divided by 10 or 20 and instead of using seconds I use tenthsesonds or twentiethseconds.
Is that a good or bad idea? Is there basically a difference between frame-based counters and timers when used on old computers?
I'm not sure about this topic therefore I ask.
Code:{ import flash.events.*; public class BasicFrameTimer extends EventDispatcher { public static const TIME_IS_UP:String = "timesup"; public var countUp:Boolean = false; public var min:int = 0; public var max:int; public var maxSet:Boolean = false; public var seconds:int; private var frameCount:int; public var started:Boolean = false; private var framesPerSecond:int; public function BasicFrameTimer(framesPerSecond:int) { this.framesPerSecond = framesPerSecond; } public function start():void { frameCount = 0; started = true; } public function stop():void { started = false; } public function reset():void { if (countUp) { seconds = 0; } else { seconds = max; } } public function update():void { if (started) { frameCount++; if (frameCount > (framesPerSecond)) { frameCount = 0; if (countUp) { seconds++; if (maxSet == true && seconds == max) { stop(); dispatchEvent(new Event(TIME_IS_UP)); } } else { seconds--; if (seconds == min) { stop(); dispatchEvent(new Event(TIME_IS_UP)); } } } } } } }




Reply With Quote