2010-09-09 28 views
0

我正試圖根據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); 

     } 
    } 

} 

問題是顯示的瓷磚間距不均勻,並且不像他們應該那樣工作。他們隨便散落在他們的排中。

+0

問題的屏幕截圖:http://s997.photobucket.com/albums/af100/shinysky/mystuff/?action=view¤t=device.png – dragonwrenn 2010-09-09 01:06:50

+0

LogCat導出:http://www.mediafire.com/?svigjmd6vgegb81 – dragonwrenn 2010-09-09 01:07:36

+0

任何其他信息需要和生病很樂意發佈它 – dragonwrenn 2010-09-09 01:08:21

回答

0

乍一看我會說你不應該在同一個循環中增加countrow和countcolumn。這是如何,我認爲它應該是這樣的:

for(int x = TopLeftCorner.column; x <= mXTileCount; x++) 
{ 
    countcolumn++; 
    for(int y = TopLeftCorner.row; y <= mYTileCount; y++) 
    { 
    countrow++; 
    ... 

編輯:

for(int x = 0; x <= mXTileCount; x++) 
{ 
    for(int y = 0; y <= mYTileCount; y++) 
    { 

    int set = mMapGrid[y + TopLeftCorner.row][x + TopLeftCorner.column]; 
    if(set == SnakeView.GRASS) 
    { 
    setTile(set, y, x); 
    } 
    else 
    { 
    setTile(SnakeView.ROCK, y, x); 
    } 
    ... 

這樣的功能通過屏幕空間座標循環,所以你不需要countrow和countcolumn了。當從mMapGrid中檢索數據時,會添加TopLeftCorner。我假定TopLeftCorner指定地圖的哪一部分當前顯示在屏幕上。確保這些座標保持有限,以便不存在實際不存在的mMapGrid中的索引。

+0

現在它是否只顯示屏幕的上半部分與瓦片 – dragonwrenn 2010-09-10 01:35:55

+0

請參閱http://s997.photobucket.com/albums/af100/shinysky/mystuff/?action=view¤t = device2.png – dragonwrenn 2010-09-10 01:37:03

+0

任何想法爲什麼它的表現如此奇怪? – dragonwrenn 2010-09-10 01:37:39