
Help! Please take a look at this code...
Hey! I''m very close to making my first tile engine from scratch (with a little help from trick of thewindows programming gurus)
My problem is that I get strange graphic anomalies when I scroll the screen around... here is my draw map function:
void
DrawWorld(void)
{
int index, index_x, index_y; // looping vars
int start_map_x,start_map_y, // map positions
end_map_x,end_map_y;
int offset_x, offset_y; // pixel offsets within cell
// clear the drawing surface
// DDraw_Fill_Surface(lpddsback, 0);
// check for movement (scrolling)
if (KEYDOWN(VK_RIGHT))
{
if ((world_x+=4) >= 1280)
world_x = 1279;
} // end if
else
if (KEYDOWN(VK_LEFT))
{
if ((world_x-=4) < 0)
world_x = 0;
} // end if
if (KEYDOWN(VK_UP))
{
if ((world_y-=4) < 0)
world_y = 0;
} // end if
else
if (KEYDOWN(VK_DOWN))
{
if ((world_y+=4) >= 896)
world_y = 895;
} // end if
// compute starting map indices by dividing position by size of cell
start_map_x = world_x/64; // use >> 6 for speed, but this is clearer
start_map_y = world_y/64;
// compute end of map rectangle for best cast i.e. aligned on 64x64 boundary
end_map_x = start_map_x + 10 - 1;
end_map_y = start_map_y + 7 - 1;
// now compute number of pixels in x,y we are within the tile, i.e
// how much is scrolled off the edge?
offset_x = -(world_x % 64);
offset_y = -(world_y % 64);
// adjust end_map_x,y for offsets
if (offset_x)
end_map_x++;
if (offset_y)
end_map_y++;
// set starting position of first upper lh texture
int texture_x = offset_x;
int texture_y = offset_y;
// draw the current window
for (index_y = start_map_y; index_y <= end_map_y; index_y++)
{
for (index_x = start_map_x; index_x <= end_map_x; index_x++)
{
// set position to blit
// textures.x = texture_x;
// textures.y = texture_y;
// set frame
currentFrame = world[index_y][index_x] - ''0'';
// draw the texture
rcRect.left = currentFrame % 10 * 64;
rcRect.top = currentFrame / 10 * 64;
rcRect.right = currentFrame % 10 * 64 + 64;
rcRect.bottom = currentFrame / 10 * 64 + 64;
hRet = g_pDDSBack->BltFast(texture_x, texture_y, g_pDDSOne,
&rcRect, DDBLTFAST_NOCOLORKEY);
// update texture position
texture_x+=64;
} // end for map_x
// reset x postion, update y
texture_x = offset_x;
texture_y += 64;
} // end for map_y
// draw some info
Draw_Text_GDI("USE ARROW KEYS TO MOVE, to Exit.",8,8,RGB(255,255,255),g_pDDSBack);
sprintf(buffer,"World Position = [%d, %d] ", world_x, world_y);
Draw_Text_GDI(buffer,8,480 - 32 - 24,RGB(0,255,0),g_pDDSBack);
// flip the surfaces
hRet = g_pDDSPrimary->Flip(NULL, 0);
}
The graphic anamolies include rapid flashing around the right hand side of the screen and the bottom, as well as tiles getting "stuck" on the side of the screen and scrolling around with user for a bit... if anyone has any ideas then PLEASE HELP!
Thanks...
-Jesse
Sorry to be bugging this forum so much but I went in over my head when I decided to make a directdraw tile engine for my first project... but I''ve almost got it. Thanks for everyone''s help!

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement