Android Canvas未更新或无效

时间:2013-03-18 06:56:46

标签: android canvas

我的资产文件夹中有newgame .txt文件。我在loadboard()方法中以字符数组(cboard)读取此文件。然后基于cboard数组中的值i填充Pboard数组(Pieces数组,逻辑数组)和bmp数组(位图数组,物理板)fillboard()。我有另一个函数populate()在画布上绘制位图图像。我有updateBoard()我更新了物理数组(bmp)和逻辑数组(Pboard)。在调用updateBoard()之后,我的逻辑数组Pboard和物理数组bmp被更新,但是当我在画布上绘制它时,它具有旧的配置。以下是我对loadboard(),fillboard(),populate功能的调用。

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // TODO Auto-generated method stub
    //  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width=View.MeasureSpec.getSize(widthMeasureSpec);
        height=View.MeasureSpec.getSize(heightMeasureSpec);
        setMeasuredDimension(width, height);`
        b=Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        c=new Canvas(b);

       loadboard();
           fillBoard();
       calculateLinePlacement();
       drawBoard();
           // method draw the board and bitmap images ( call populate()).


    }

updateBoard()函数后,我调用invalidate();

EDIT1:

以下是updateBoard()方法(从commnet复制):

public void updateBoard(int sr, int sc, int er, int ec) {
Pboard[sr][sc] = new Empty(sr, sc, -3, "empty", board);
Pboard[er][ec] = selectedp;
Bitmap img = bmp[sr][sc];
bmp[sr][sc] = null;
bmp[er][ec] = null;
bmp[er][ec] = img;
}

0 个答案:

没有答案
相关问题