Проблема TMX с рисованием тайлов в правильном положении (c ++)

Карта TMX загружается правильно, но, похоже, неправильно размещает мои плитки.

Я использую парсер TMX отсюда: https://code.google.com/p/tmx-parser/

Он загружает TMX нормально, без ошибок. Но это только расположение плиток в соответствии с их расположением в таблице спрайтов.

Вот пример кода:

void Game::DrawMap()
{
SDL_Rect rect_CurTile;
SDL_Rect pos;
int DrawX;
int DrawY;

for (int i = 0; i < map->GetNumLayers(); ++i)
{
// Get a layer.
currLayer = map->GetLayer(i);

for (int x = 0; x < currLayer->GetWidth(); ++x)
{
for (int y = 0; y < currLayer->GetHeight(); ++y)
{
int CurTile = currLayer->GetTileId(x, y);

int Num_Of_Cols = 8;

int tileset_col = (CurTile % Num_Of_Cols);
tileset_col++;
int tileset_row = (CurTile / Num_Of_Cols);

rect_CurTile.x = (1 + (32 + 1) * tileset_col);
rect_CurTile.y = (1 + (32 + 1) * tileset_row);
rect_CurTile.w = 32;
rect_CurTile.h = 32;

DrawX = (x * 32);
DrawY = (y * 32);

pos.x = DrawX;
pos.y = DrawY;
pos.w = 32;
pos.h = 32;

apply_surfaceClip(DrawX,DrawY, surfaceTileset, destSurface, &rect_CurTile);
sprTexture = SDL_CreateTextureFromSurface(mRenderer,destSurface);
SDL_RenderCopy(mRenderer,sprTexture,&rect_CurTile,&pos);
}
}
}

void apply_surfaceClip( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
SDL_Rect offset;

//Get offsets
offset.x = x;
offset.y = y;

//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}

0

Решение

Я исправил проблему, когда при использовании двух слоев он рисовал нули, вот готовый образец

for (int i = 0; i < map->GetNumLayers(); ++i)
{
// Get a layer.
currLayer = map->GetLayer(i);

for (int x = 0; x < currLayer->GetWidth(); ++x)
{
for (int y = 0; y < currLayer->GetHeight(); ++y)
{
int CurTile = currLayer->GetTileId(x, y);

if(CurTile == 0)
{
continue;
}

int Num_Of_Cols = 8;

int tileset_col = (CurTile % Num_Of_Cols);
int tileset_row = (CurTile / Num_Of_Cols);

std::cout << CurTile << std::endl;

rect_CurTile.x = (1 + (32 + 1) * tileset_col);
rect_CurTile.y = (1 + (32 + 1) * tileset_row);
rect_CurTile.w = 32;
rect_CurTile.h = 32;

DrawX = (x * 32);
DrawY = (y * 32);

pos.x = DrawX;
pos.y = DrawY;
pos.w = 32;
pos.h = 32;

apply_surfaceClip(DrawX,DrawY, surfaceTileset, destSurface, &rect_CurTile);
sprTexture = SDL_CreateTextureFromSurface(mRenderer,destSurface);
SDL_RenderCopy(mRenderer,sprTexture,&rect_CurTile,&pos);
}
}
}
0

Другие решения


По вопросам рекламы [email protected]