Search code examples
androidperformancegraphicsframe-rate

Graphics Choppy


I was trying to make an into transition to my game by having two bitmaps slide apart, like a garage door opening from the middle and half sliding downwards and half upwards. Anyway, when I do it, it looks really choppy and the frame rate seems unstable/unreliable. Here's how I'm doing it.

public class TFView extends View{
...
public void startlevel(Canvas c){
     long l =(SystemClock.currentThreadTimeMillis()-starttime)/3;//*(height/500);
    if(l<1000){
        c.drawBitmap(metalbottom,0,height/2+l,p);
         c.drawBitmap(metaltop,0,0-l,p);}
    }
 public void endlevel(Canvas c){
     long l =(SystemClock.currentThreadTimeMillis()-failtime)/3;
    if(l>=height/2){
        c.drawBitmap(metaltop, 0, 0, p);
        c.drawBitmap(metalbottom, 0,height/2 , p);
    }
    else{
        c.drawBitmap(metalbottom,0,-height/2+l,p);
     c.drawBitmap(metaltop,0,height-l,p);}
 }}

and i set the times for when I want to open/close the doors respectively. So what do you think I should change to make it a more smooth transition? Would converting it to surfaceview help?


Solution

  • I had the same problem. I know what you mean with "choppy". The animation speed is NOT consistent even though you have a time based animation i.e. you are using

    SystemClock.currentThreadTimeMillis()
    

    The choppiness is caused by currentThreadTimeMillis(). It "returns milliseconds running in the current thread". That is, when you use currentThreadTimeMillis() "time" only elapses when the current thread is RUNNING. But your renderer thread is NOT ALWAYS running - as you would expect in a multitasking environment. Thus every time the thread is not running your animation is also not "running" (time is not elapsing).

    Solution: Use

    SystemClock.elapsedRealtime()