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

re: scrolling and tiles wrapping around

This topic is 5620 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. Im implementing a tile engine. After much hard work, I was able to get a single screen to display correctly. However, regarding the scrolling, the tiles that should be off the screen on the right, are displayed on the left as if they are wrapping around. Here is my code:
#define TILE_SIZE       32
#define WORLD_SIZEX     25
#define WORLD_SIZEY     20
#define SCREEN_SIZEX    12
#define SCREEN_SIZEY    12
int world_camerax = 0;
int world_cameray = 0;

     {2, 2, 1,2....//etc all filled with 1''s and 2''s


void draw_tiles(void)
   int tile;
   int x;
   int y;

    int scroll_x, scroll_y;   // (NEW) 

  int offset_x, offset_y;   // (NEW) 

   RECT tile_src;
	POINT point;
   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

         // (NEW)

      scroll_x = x + (world_camerax / TILE_SIZE);  
      scroll_y = y + (world_cameray / TILE_SIZE);

      // (NEW)

      offset_x = world_camerax & (TILE_SIZE - 1);
      offset_y = world_cameray & (TILE_SIZE - 1);

		 tile_src.left    =  (tile - 1) * TILE_SIZE;     =  0;
         tile_src.right   =  TILE_SIZE;
         tile_src.bottom  =  TILE_SIZE;
		point.x = (x *TILE_SIZE) - offset_x;
		point.y = (y * TILE_SIZE) - offset_y;


Is this a problem with clipping? And if so how do I go about clipping in DirectX. Thanks for your help Feel free to email me at if you have any questions

Share this post

Link to post
Share on other sites