0

I'm building a library in haxe/openfl to make games, and I've noticed some jerking in the movement of sprites, especially when running on android or flash set to debug, and after using trace(elapsed) on my code I noticed that there are spikes every few frames of a substantial amount, which I believe to be causeing the jerking:

Game.hx:64: 0.030999999999998806
**Game.hx:64: 0.0470000000000006**
Game.hx:64: 0.030999999999998806
Game.hx:64: 0.03100000000000236
Game.hx:64: 0.03200000000000003
**Game.hx:64: 0.045999999999999375**
Game.hx:64: 0.03200000000000003
Game.hx:64: 0.030999999999998806
Game.hx:64: 0.030999999999998806
Game.hx:64: 0.03100000000000236
Game.hx:64: 0.03200000000000003
Game.hx:64: 0.030999999999998806
Game.hx:64: 0.030999999999998806
Game.hx:64: 0.03100000000000236
**Game.hx:64: 0.0470000000000006**
Game.hx:64: 0.03200000000000003
Game.hx:64: 0.030999999999998806
Game.hx:64: 0.030999999999998806

Here is the code used to determine the elapsed time:

private function UpdateElapsedTime()
    {
        var current = Lib.getTimer() / 1000.0;
        elapsed = current - lastElapsed;
        lastElapsed = current;
    }

Can anyone point out what is going wrong, or what I could do to improve it, thanks, nico

Nico
  • 94
  • 9

1 Answers1

1

That may be caused by the garbage collector, using Adobe Scout should help you out trying to understand the problem.

If you don't want to use Adobe Scout, or if you just want to always have a little "benchmark" you can use https://github.com/mrdoob/Hi-ReS-Stats which will a little graph of the memory used and FPS which will help you to discover when the garbage collector "collects" (you'll see the memory used decreasing) and you can detect slow frames without using trace.

npretto
  • 1,098
  • 7
  • 18
  • hmm well I don't think it is that, as while it does dump memory occasionally, it is not very often, whereas the stutter is more than once a second, however i'm gonna mark your answer correct, as it is a good one, and the stats monitor is handy....although it did not work for me in haxe off the bat, something in the xml declarations is wrong, so I did a quick and dirty hack, and displayed it as standard text – Nico Feb 20 '14 at 02:05
  • If the stats didn't help I'd really advice you to use scout, it should still be free but you need to make an Adobe account and add a flag when you compile, but it's well worth it and it helped me optimize things in the past. – npretto Feb 20 '14 at 09:17