2012-01-28 3 views
1

私はtiled(http://mapeditor.org)で作成されたマップをtmx-parser(http://code.google.com .com/p/tmx-parser /)。正しい位置にレンダリングするタイルがありますが、タイルセットから正しいタイルをレンダリングすることができません。私はそれをテストするためにタイル張りのisometric_grass_and_waterの例を使用しています。tmx-parserと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); 
      } 
     } 
    } 
} 

誰かが間違っていることを指摘できますか?

答えて

1

誰がそれを必要とする場合、ここでいくつかのブルートフォースが変更作業をコードした後、私は答えを見つけた: PS:Num_Of_Colsは

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; 
      } 

      //CurTile = tileset->GetFirstGid() + CurTile; 
      CurTile--; 

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

      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); 
     } 
    } 
} 
} 
(TilesetWidth/tileWidthプロパティ)と同じものです
関連する問題