我一直在尝试实现一个函数,让我可以在平铺文件(.tmx)中绘制平铺。我环顾四周,发现了一种有效的代码,但它拉伸了瓷砖。
这是我找到并编辑了一下的代码:
private void DrawLayer(int index, SpriteBatch batch) {
for (var i = 0; i < Map.Layers[index].Tiles.Count; i++) {
//Get the identification of the tile
int gid = Map.Layers[index].Tiles[i].Gid;
// Empty tile, do nothing
if (gid == 0) { }
else {
int tileFrame = gid - 1 ;
int column = tileFrame % (tileset.Width / tileWidth);
int row = tileFrame / (tileset.Height / tileHeight);
float x = (i % Map.Width) * Map.TileWidth;
float y = (float)Math.Floor(i / …Run Code Online (Sandbox Code Playgroud)