I am attempting to resolve this “issue” I have where when I set the interval of my CustomTimer to 500 (500 ms) it does not seem to take effect as expected.
The code looks like this:
class CustomTimer
{
public var timeStarted:Float;
public var interval:Float;
public var currentTime:Float;
private var _seconds:Int;
public var tick:Signal1<Int>;
public function new(interval:Float)
{
timeStarted = 0;
currentTime = 0;
this.interval = interval;
tick = new Signal1<Int>();
}
public function update(deltaTime:Float)
{
currentTime += deltaTime;
if (currentTime % interval >= 1)
{
tick.dispatch(++_seconds);
currentTime = 0;
}
}
}
So every time the currentTime
reaches interval
, it will reset and the tick
event will dispatch. But after building, it still appears as if the animation is happening every 50ms. I’m not sure if it’s because Lib.getTimer() uses microseconds or milliseconds (I would have thought ms) but maybe someone can correct me on that.
If you wish to replicate the results I’m getting, check out my branch on Github:
Currently, the target that works is native c++, not neko. I’m getting an error in Neko every time I try to do that (maybe it’s too fast and doesn’t like it?)