Android的帆布:我如何清除(删除的内容)画布(=位图),生活在一个surfaceView?位图、画布、帆布、内容

2023-09-11 12:36:30 作者:少年年少

我试图做一个简单的游戏。

我发现(并投入使用)利用帆布像这样的位图的模板:

 私人无效doDraw(帆布油画){
    的for(int i = 0; I< 8;我++)
        对于(INT J = 0; J< 9; J ++)
            为(中间体K = 0; K&小于7; k ++){
    canvas.drawBitmap(兆位[ALLBITS [I] [J] [K],I * 50 * -k 7,J * 50 * -k 7,NULL); }}
 

(画布在运行()中定义/在SurfaceView住在一个GameThread。)

现在:

如何清除(或重绘)整个画布的一个新的布局(=尝试在游戏)? 而且:我怎么可以更新的画面只是一部分的

的非常感谢你为一个务实的提示给我!的

(从AT计算器浏览主题时,我想很多人想听到的答案...)的

  //这就是所谓的doDraw常规:
公共无效的run(){
    而(mRun){
        帆布C = NULL;
        尝试 {
            C = mSurfaceHolder.lockCanvas(空);
            同步(mSurfaceHolder){
                如果(mMode服务== STATE_RUNNING)
                    updateGame();
                doDraw(C); }
        } 最后 {
            如果(C!= NULL){
                mSurfaceHolder.unlockCanvasAndPost(C); }}}}
 
3dmax匹配的位图背景如何去掉 因为渲染的时候总是在背景中出现位图,所以想把位图背景去掉,如何去掉

解决方案   

如何清除(或重绘)整个画布的一个新的布局(=尝试在游戏)?

还是叫Canvas.drawColor(Color.BLACK),或任何您想要的颜色,以清除画布

  

和:?我怎么可以更新的画面只是一部分

有,只是更新屏幕的一部分,因为Android操作系统的更新屏幕重绘时,每个像素没有这样的方法。但是,当你不能在你的画布清除旧图纸,老图纸仍然在表面上,这是很可能的一种方式,以更新只是一部分的屏幕。

所以,如果你想更新屏幕中的一部分,只是避免调用 Canvas.drawColor()方法。

I try to make a simple game.

I found (and put to use) a template that draws a canvas with bitmaps like this:

private void doDraw(Canvas canvas) {
    for (int i=0;i<8;i++)
        for (int j=0;j<9;j++)
            for (int k=0;k<7;k++)   {
    canvas.drawBitmap(mBits[allBits[i][j][k]], i*50 -k*7, j*50 -k*7, null); } }

(The canvas is defined in "run()" / the SurfaceView lives in a GameThread.)

Now:

How do I clear (or redraw) the WHOLE canvas for a new layout (= try at the game) ? And: how can I update just a part of the screen ?

THANK YOU very much for a pragmatic hint to me!

(From browsing topics at stackoverflow I think a lot of people would like to hear that answer...)

// This is the routine that calls "doDraw":
public void run() {
    while (mRun) {
        Canvas c = null;
        try {
            c = mSurfaceHolder.lockCanvas(null);
            synchronized (mSurfaceHolder) {
                if (mMode == STATE_RUNNING) 
                    updateGame();
                doDraw(c);          }
        } finally {
            if (c != null) {
                mSurfaceHolder.unlockCanvasAndPost(c);  }   }   }       }

解决方案

How do I clear (or redraw) the WHOLE canvas for a new layout (= try at the game) ?

Just call Canvas.drawColor(Color.BLACK), or whatever color you want to clear your Canvas with.

And: how can I update just a part of the screen ?

There is no such method that just update a "part of the screen" since Android OS is redrawing every pixel when updating the screen. But, when you're not clearing old drawings on your Canvas, the old drawings are still on the surface and that is probably one way to "update just a part" of the screen.

So, if you want to "update a part of the screen", just avoid calling Canvas.drawColor() method.