Original Post
Below is some code of tile blting and scrolling. As you will see I scroll the screen by 40s. My tile size is 40 and my screen res is 800x600. If I try to scroll with any number other than 40, it starts repeating the tiles and distoring on the sides. This is a side scroller BTW. Please include sample code if you can. This problem has stumped me for quite some time now, I have not worked on my game because of it. I know I have posted about this a million times, but I just don''t know what to do so here''s the code:
THX!
int x,y,camerax = 0;
char map[15] [60] = {
{2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{3,3,3,3,3,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3,3,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3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Main(void *parms = NULL, int num_parms = 0)
{
int tileid;
RECT tilescanrect;
for(int x = 0; x< 60; x++)
{
for(int y = 0; y < 15; y++)
{
tileid = map[y][x];
tilescanrect.left = (tileid-1) * 40;
tilescanrect.top = 0;
tilescanrect.right = tileid * 40;
tilescanrect.bottom = 40;
backsurf->BltFast(camerax+x* 40, y * 40,
tilesurf,
&tilescanrect,
NULL);
}
}
if (KEYDOWN(VK_LEFT))
{
thesprite.celly = 0;
MoveSprite(thesprite,west);
AnimateSprite(thesprite,character,backsurf);
//global coordinate for camera, blts with this above
camerax+=40;
//check boundaries of level
if(camerax >= 0)
camerax = 0; //stop camera
if(thesprite.x <= 0) //check boundaries of sprite
thesprite.x = 0; //stop sprite
}
if (KEYDOWN(VK_RIGHT))
{
thesprite.celly = 1;
AnimateSprite(thesprite,character,backsurf);
MoveSprite(thesprite,east);
//global coordinate for camera, blts with this above
camerax-=40;
//check boundaries of level
if(camerax <= -800)
{
camerax = -800; //stop camera
}
//check boundaries of sprite
if(thesprite.x >= 760)
thesprite.x = 760; //stop sprite
}
BltSprite(thesprite,
character,
backsurf,
DDBLTFAST_SRCCOLORKEY);
BltSprite(bullet,character,backsurf,DDBLTFAST_SRCCOLORKEY);
FlipSurfaces();
return(1);
} // end Game_Main
|