有了這個代碼我繪製等距棋盤出的單一板件bmpWhite
和bmpBlack
的Android等距棋盤
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (white == true) {
color[i][j] = 0;
white = false;
}
else {
color[i][j] = 1;
white = true;
}
}
}
}
public void onDraw(Canvas canvas)
{
if (gameViewWidth == 0)
{
gameViewWidth = theGameView.getWidth();
gameViewHeight = theGameView.getHeight();
}
for (int xx=0; xx < 7; xx++)
{
for (int yy=0; yy < 7; yy++)
{
int x_start=(yy * 23);
int y_start=(gameViewHeight/2) + (yy * 12);
int xx1=x_start + (xx * 23);
int yy1=y_start - (xx * 12);
if (color[xx][yy] == 0)
{
canvas.drawBitmap(bmpWhite, xx1, yy1, null);
}
else if (color [xx][yy] == 1)
{
canvas.drawBitmap(bmpBlack, xx1, yy1, null);
}
}
}
輸出應一個chessboar(8×8)具有交替的顏色。但輸出是這樣的:
正如你所看到的底部和頂部的最後兩行是相同的顏色。 我做錯了什麼?
好吧,現在我知道最新的問題:當應用程序繪製最後一行時,將其繪製爲2行。但爲什麼? – Stupe
我認爲在每一個循環中,你都會對棋盤上留下的東西進行着色。我完全不理解你的代碼。 – Paniz