所以我想清除畫布使用canvas.drawcolor(Color.BLACK),但如果我只是調用一次,顯示器閃爍並顯示應該已經被drawColor覆蓋。Android SurfaceView/Canvas閃爍後,試圖清除它
這裏是我的代碼的重要位 -
public void update() {
//This method is called by a Thread
Canvas canvas = holder.lockCanvas(null);
if (canvas != null) {
onDraw(canvas);
}
holder.unlockCanvasAndPost(canvas);
}
@Override
protected void onDraw(Canvas canvas) {
if (toClear) {
canvas.drawColor(Color.BLACK);
//if this is not set to change back to false, it does not flicker
toClear = false;
}
//Draw some objects that are moving around
}
public void clearScreen() {
//This method is called when the user pressed a button
toClear = true;
}
周圍的Googling豆蔻後,我聽說過雙緩衝,但來到理解是lockCanvas()和unlockCanvasAndPost()應該處理這對我來說。這裏出了什麼問題?
這個工作,雖然我不得不說它是非常直觀的 –