好的,所以我正在尝试显示一个瓷砖地图,但我的数学似乎已经关闭了。
private void MapPanel_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
GraphicsUnit units = GraphicsUnit.Pixel;
for (int i = 0; i < map.tiles.Length; i++)
{
for (int j = 0; j < map.tiles[i].Length; j++)
{
int tileXCoord = 0;
int tileYCoord = 0;
int tileSheetWidth = tileMap.Width / map.tileSize;
if (map.tiles[i][j] != 0)
{
tileXCoord = tileSheetWidth % map.tiles[i][j];
tileYCoord = tileSheetWidth / map.tiles[i][j];
}
Rectangle destRect = new Rectangle((i * map.tileSize) - hScrollValue, (j * map.tileSize) - vScrollValue, map.tileSize, map.tileSize);
g.DrawImage(tileMap, destRect, tileXCoord * map.tileSize, tileYCoord * map.tileSize, map.tileSize, map.tileSize, units);
}
}
}
现在我正在尝试让我的地图使用“自动换行”磁贴索引
[0][1]
[2][3]
但它没有用,有人知道为什么吗?
答案 0 :(得分:0)
我用
tileXCoord = ((currentTile % tilesize) * Imagewidth);
tileYCoord = ((currentTile / tileSize) * Imagewidth);
哪种方式适合我。请注意,我绝不是这类事情的专家。
答案 1 :(得分:0)
private void MapPanel_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
GraphicsUnit units = GraphicsUnit.Pixel;
for (int i = 0; i < map.tiles.Length; i++)
{
for (int j = 0; j < map.tiles[i].Length; j++)
{
int tileXCoord = 0;
int tileYCoord = 0;
int tileSheetWidth = tileMap.Width / map.tileSize;
if (map.tiles[i][j] != 0)
{
tileXCoord = map.tiles[i][j] % tileSheetWidth;
tileYCoord = map.tiles[i][j] / tileSheetWidth;
}
Rectangle destRect = new Rectangle((i * map.tileSize) - hScrollValue, (j * map.tileSize) - vScrollValue, map.tileSize, map.tileSize);
g.DrawImage(tileMap, destRect, tileXCoord * map.tileSize, tileYCoord * map.tileSize, map.tileSize, map.tileSize, units);
}
}
}