除了爲每個平鋪創建單獨的案例之外,更好的方法是什麼?如何創建平鋪系統
public void Draw(SpriteBatch spriteBatch, Level level)
{
for (int row = 0; row < level._intMap.GetLength(1); row++) {
for (int col = 0; col < level._intMap.GetLength(0); col++) {
switch (level._intMap[col, row]) {
case 0:
spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(0 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
break;
case 1:
spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(1 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
break;
case 2:
spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(2 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
break;
case 3:
spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(3 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
break;
}
}
}
}
的tileap是一個二維數組INT [,],我想一個位圖分成多個 –