1
我正在使用tmx-parser解析地圖(http://code.google.com)後獲取在Tiled(http://mapeditor.org)中創建的地圖進行渲染的.com/p/TMX-解析器/)。我已經在正確的位置呈現瓷磚,但我似乎無法讓它從瓷磚組中呈現正確的瓷磚。我使用來自平鋪的isometric_grass_and_water示例來測試它。使用tmx解析器和SDL進行2d圖塊渲染
這是我的渲染代碼。
void Map::RenderMapIsometric(SDL_Surface *SurfaceDest)
{
for (int i = 0; i < map->GetNumLayers(); ++i)
{
// Get a layer.
this->layer = map->GetLayer(i);
for (int x = 0; x < layer->GetWidth(); ++x)
{
for (int y = 0; y < layer->GetHeight(); ++y)
{
int CurTile = layer->GetTileGid(x, y);
if(CurTile == 0)
{
continue;
}
int tileset_col = (CurTile % (TilesetWidth/this->tileset->GetTileWidth()));
int tileset_row = (CurTile/(TilesetWidth/this->tileset->GetTileWidth()));
std::cout << CurTile << std::endl;
SDL_Rect rect_CurTile;
rect_CurTile.x = (this->tileset->GetMargin() + (this->tileset->GetTileWidth() + this->tileset->GetSpacing()) * tileset_col);
rect_CurTile.y = (this->tileset->GetMargin() + (this->tileset->GetTileHeight() + this->tileset->GetSpacing()) * tileset_row);
rect_CurTile.w = this->tileset->GetTileWidth();
rect_CurTile.h = this->tileset->GetTileHeight();
int DrawX = (x * this->tileset->GetTileWidth()/2) + (y * this->tileset->GetTileWidth()/2);
int DrawY = (y * this->tileset->GetTileHeight()/2) - (x * this->tileset->GetTileHeight()/2);
apply_surfaceClip(DrawX, DrawY, surf_Tileset, SurfaceDest, &rect_CurTile);
}
}
}
}
任何人都可以指出我做錯了什麼?