knotri
knotri

Reputation: 253

Android SurfaceView strange behavior

if(pauseGame){
    if(update){
        update = false;
        My_static_draw();
    }else{
        try {
           Thread.sleep(160);
        } catch (InterruptedException e) {
           e.printStackTrace();
        }
    }
}else{
   My_Game_draw(); //its load CPU
}

When I do pauseGame = true; it's work(load CPU ~0%) , but I see something strange on the display changing two(or more) image , image 1 drawn in the My_static_draw() , and some few last image in the My_Game_draw();

Upvotes: 0

Views: 95

Answers (1)

fadden
fadden

Reputation: 52353

I'm guessing you're calling Surface.lockCanvas() before calling into the code included in your answer. If you do that, you have to redraw the entire dirty region (which, by default, is the entire screen).

You're cycling through previous frames because SurfaceView is double- or triple-buffered. If you lock and unlock without drawing anything, you're just re-submitting a previously-drawn buffer.

You can fix this by not calling lockCanvas()/unlockCanvasAndPost() at all if you have nothing to draw.

Upvotes: 1

Related Questions