我正試圖根據Snake示例大量製作一個二維瓷磚系統。原始的mTileGrid仍然存在,但有一個新的數組:mMapGrid。重點是在每個更新週期將數據從mMapGrid複製到mTileGrid,並因此模擬大於即時屏幕的區域。2D瓷磚系統不能正常工作
我寫了更多的功能,這是我現在簡單介紹一下......在那之後,這個問題:
在地圖網格 公共無效setMapTile(INT tileindex,詮釋行,詮釋列) 集瓦mMapGrid [row] [column] = tileindex; }
在的onDraw()調用,從移動的mMapGrid數據mTileGrid
private void CopyArrayData()
{
//TODO: TAG
int countrow, countcolumn;
countrow = 0;
countcolumn = 0;
Log.w( 「PassNumbers」, 「TopLeftCorner.column是:」 + TopLeftCorner.column +「和TopLeftCorner。行是「+ TopLeftCorner.row);
for(int x = TopLeftCorner.column; x <= mXTileCount; x++)
{
for(int y = TopLeftCorner.row; y <= mYTileCount; y++)
{
countrow++;
countcolumn++;
if(countrow == mXTileCount)
{
countrow = 0;
}
if(countcolumn == mYTileCount)
{
countcolumn = 0;
}
int set = mMapGrid[y + TopLeftCorner.row][x + TopLeftCorner.column];
if(set == SnakeView.GRASS)
{
setTile(set, countrow, countcolumn);
}
else
{
setTile(SnakeView.ROCK, countrow, countcolumn);
}
if(pass1 == false)
{
Log.w("TileGridAccess",("TileGrid Access: row" + countrow + " column" + countcolumn));
Log.w("MapGridAccess","MapGrid Access: row" + (y + TopLeftCorner.row) + " column:" + (x + TopLeftCorner.column));
}
}
pass1 = true;
}
}
}
的update()函數,用setMapTile()這裏叫做
public void update() {
if (mMode == RUNNING) {
clearTiles();
setMapTile(GRASS, 5, 5);
setMapTile(GRASS, 5, 6);
setMapTile(GRASS, 5, 7);
setMapTile(GRASS, 5, 8);
setMapTile(GRASS, 5, 9);
mRedrawHandler.sleep(mMoveDelay);
}
}
的的onDraw()函數:(從蛇原來TileView不變,除了消除如果大於零的檢查,因爲我們有一個默認的瓷磚)
@Override public void onDraw(Canvas canvas){ super.onDraw(canvas);
CopyArrayData();
for (int x = 0; x < mXTileCount; x += 1) {
for (int y = 0; y < mYTileCount; y += 1) {
canvas.drawBitmap(mTileArray[mTileGrid[x][y]],
mXOffset + x * mTileSize,
mYOffset + y * mTileSize,
mPaint);
}
}
}
問題是顯示的瓷磚間距不均勻,並且不像他們應該那樣工作。他們隨便散落在他們的排中。
問題的屏幕截圖:http://s997.photobucket.com/albums/af100/shinysky/mystuff/?action=view¤t=device.png – dragonwrenn 2010-09-09 01:06:50
LogCat導出:http://www.mediafire.com/?svigjmd6vgegb81 – dragonwrenn 2010-09-09 01:07:36
任何其他信息需要和生病很樂意發佈它 – dragonwrenn 2010-09-09 01:08:21