I have a problem where i draw tiles (sprites) on a screen. The Tiles will be moved left, right, down, up as those arrow keys are pressed. The entire screen is to be covered.
The big thing is I want to be able to stop the screen before the furthest most right (or down) tile can move past its last pixel (thus leaving a blank spot.
void mxDrawScreen(void)
{
//int xTile;
//int yTile;
int spriteCount=1;
for (int yTile=0;yTile<(dbScreenHeight()/89)+1;yTile++)
{
for (int xTile=0;xTile<(dbScreenWidth()/89)+1;xTile++)
{
if (yPos<=(pixelHeight-dbScreenHeight())*-1)
{
yPos=(pixelHeight-dbScreenHeight())*-1;
}
if (xPos<=(pixelWidth-dbScreenWidth())*-1)
{
xPos=(pixelWidth-dbScreenWidth())*-1;
}
if (xPos>0)
{
xPos=0;
}
if (yPos>0)
{
yPos=0;
}
dbSprite(spriteCount,(xTile*89)+xPos,(yTile*89)+yPos,memMap[xTile][yTile]);
//dbSizeSprite(spriteCount,89,89);
spriteCount++;
}
}
}
For reference pixelHeight is the number of the last pixel of the lowest tile. and pixelWidth containts the number of the last pixel of the right most tile
Heres what happens.. On the Y axis, it stops about two tiles too late (so in my case blank blue). On the X axis, it stops about 15 tiles too late? I have confirmed that pixelHeight,pixelWidth,dbScreenWidth, dbScreenHeight are all returning the correct numbers.
Thanks for your help.
edit: this might also be helpful
if(dbUpKey() == 1)
{
yPos--;
}
if(dbDownKey() == 1)
{
yPos++;
}
if(dbLeftKey() == 1)
{
xPos--;
}
if(dbRightKey() == 1)
{
xPos++;
}
// dbRotateSprite(1,90);
if(dbEscapeKey() == 1)
{
break;
}