Hello and Welcome I am trying to make a 2-D tile system heavily based off of the Snake example. The original mTileGrid is still there, but there is a new array: mMapGrid. The point is to copy the data from mMapGrid to mTileGrid on each update cycle and therefore simulate an area larger than the immediate screen.
I wrote more functions, which I will now briefly explain... After that, the problem:
Set a tile in the map grid public void setMapTile(int tileindex, int row, int column) { mMapGrid[row][column] = tileindex; }
Called in onDraw(), moves the data from mMapGrid to mTileGrid
private void CopyArrayData()
{
//TODO: TAG
int countrow, countcolumn;
countrow = 0;
countcolumn = 0;
Log.w("PassNumbers", "TopLeftCorner.column is: " + TopLeftCorner.column + " and TopLeftCorner.row is " + 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;
}
}
}
The update() function, with setMapTile() called here
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);
}
}
The onDraw() function: (unchanged from the original TileView in Snake, except for the elimination of the if greater than zero check since we have a default tile)
@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);
}
}
}
The problem is that the tiles displayed are not evenly spaced and do not behave as they should. They are haphazardly scattered about their row.