Archived

This topic is now archived and is closed to further replies.

Tile mapping problem

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. [This is the same post that I put in DirectX, but no one has responded there so I''m trying this forum] Im writing a platformer, and I was looking at gamedev articles to try to learn about tile-based engines. The article I found useful is http://www.gamedev.net/reference/programming/features/tiling1/page3.asp . Unfortunately, the tiles are not quite rendering properly. All of the tiles are there, but it seems as if changing the type of tile in one location will change it in both that location and another one. I was thinking this might have something to do with clipping but I am not sure. here is the code I use to render the tiles:
  
  void draw_tiles(void){  
    int tile;
    int x;
   int y; 
  RECT      tile_src;	
  POINT point;
/* world sizey is defined as 15 (enough to fit in a 640*480 res).worldsizex is defined as 20...same reason. so it should fit perfectly on a 640*480 resolution. tilesize is 32*32  */

 for (y = 0; y < WORLD_SIZEY; y++)   { 
     for (x = 0; x < WORLD_SIZEX; x++)      { 
        tile = map[y][x];   //tile stores id now

  tile_src.left    =  (tile - 1) * TILE_SIZE;
   tile_src.top     =  0;   
   tile_src.right   =  tile * TILE_SIZE;
  tile_src.bottom  =  TILE_SIZE;
   point.x = x *TILE_SIZE;
   point.y = y * TILE_SIZE;
  CopySurfaceToSurface  (&tile_src,g_tiles,&point,g_pBackSurface,TRUE,D3DCOLOR_ARGB(255,255,0,255));      }   
  }
}  

  
Here is the data for the level, although I doubt you will find that significant....
  

  char map[15][20] = {
   {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},
   {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1}, 
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1}, 
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},
   {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1}, 
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1},  
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,2,1,1}, 
  {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,3,3,3,3,3,3,1,1}};  

  
For example, when I change the 1 on the very bottom row, 2nd from the right to a 3, then the left corner of the screen changes to the color of a 2. I would love some help and really appreciate any ideas.

Share this post


Link to post
Share on other sites