Skip to main content
gamedev.net
🔒 Locked

re: rendering wrong tiles

Started by GameDev135 0 replies 250+ views
Original Post
GameDev135
GameDev135
Hi. [I put this in a forum b4, without realizing that there was this one specifically on tile based games....sorry] 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 resolutiontilesize is 32*32 */

  for (y = 0; y < WORLD_SIZEY; y++)   {      
for (x = 0; x < WORLD_SIZEX; x++)      {  
       tile = map[y][x];    
// tile now stores the ID of this particular tile

   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 it Feel free to email me at NYYanks432@hotmail.com if you have any questions
Feel free to email me at NYYanks432@hotmail.com if you have any questions

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.