试图清除后的And​​r​​oid SurfaceView /帆布闪烁 [英] Android SurfaceView/Canvas flickering after trying to clear it

查看:130
本文介绍了试图清除后的And​​r​​oid SurfaceView /帆布闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想明确使用canvas.drawColor(Color.BLACK)画布,但如果我只是把这种一次,显示屏闪烁,显示旧图纸应已涵盖了由drawColor。

So I am trying to clear the Canvas using canvas.drawColor(Color.BLACK) but if I just call this once, the display flickers and displays the old drawing which should have been covered up by the drawColor.

下面是我的code中的重要位 -

Here is the important bits of my code -

    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;
}

围绕豆蔻谷歌搜索后,我听说了双缓冲,但来到这lockCanvas()和unlockCanvasAndPost()应该处理这对我的理解。这是怎么回事错在这里?

After Googling around a litte, I heard about double buffering but came to the understanding that lockCanvas() and unlockCanvasAndPost() should handle this for me. What is going wrong here?

推荐答案

我不知道这是做 SurfaceView 被双缓冲,他们轮流每一帧。因此,你将不得不清除屏幕至少两帧。

I wonder if this is to do with SurfaceView being double buffered and they alternate each frame. Hence you would have to clear the screen at least two frames.

修改 toClear = TRUE toClear = 2 ,设置

if(toClear > 0) { 
   'drawColor'
   toClear--; 
}

这篇关于试图清除后的And​​r​​oid SurfaceView /帆布闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆