Hey all, I'm using the loop below and it works great until I introduce a notifier to cap my rendering to 30 FPS (Basically so that it doesn't render redundant frames and only renders when an update has occured)
Initially I was having problems with the sprites being choppy so added interpolation and it really helped to smooth things out, but as I say, on capping the rendering it has re-introduces intermittent (although not terrible) choppiness.
Any ideas? Thanks!

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| @Override public void run() { nextGameTick = System.nanoTime(); Canvas c; while (running) { c=null; loops = 0; if (gameTimer==0){gameTimer=System.nanoTime(); } while(System.nanoTime() > nextGameTick && loops < maxFrameskip){ updateMenu(); nextGameTick += skipTicks; loops++; } float interpolation = (float)(System.nanoTime() + skipTicks - nextGameTick) / (float)(skipTicks); if (updateGame == true) { try{c=mySurfaceHolder.lockCanvas(null); synchronized(mySurfaceHolder){ draw(c, interpolation); updateGame=false; } } finally{ if (c != null){ mySurfaceHolder.unlockCanvasAndPost(c); } } } } } } } |
I'm setting updateGame to true in my updateMenu() method.
PS - After changing Systemclock.elapsedRealtime() to System.Nanotime() it seems to have helped a little, but it's still not perfect.
I'm not creating any objects at run time and GC isn't being triggered but this is probably not relevant anyway as if I don't cap the rendering, it seems to run a lot smoother (which is kind of odd, as it's only then rendering the same frame as before i.e., no sprite movements).
My guess is that my capping/notification is somehow playing havoc with interpolation calculation? (timing issue?)
Thanks again!