Im making a platform game for the learning experience, and im having a problem.
The tiles are overlapping eachother by one pixel. Or at least that's what i think is happening. The result is a gray line between tiles and my coordinates are thrown further and further off as the player goes right.
Ive included an illustration: http://i276.photobuc...tileProblem.png
The purple writing shows that the tile is shown as 19 pixels when it should be 20, and that there is a unintentional gray line.
Here is the code that reads in the map file:
void Map::LoadMap(const char *file){
tileImage[0].LoadFromFile("Load/tile0.png");
tileImage[1].LoadFromFile("Load/tile1.png");
tileImage[2].LoadFromFile("Load/tile2.png");
std::ifstream infile(file);
int t[32][24];
for( int j = 0; j < MAPHEIGHT; j++){
for( int i = 0; i < MAPWIDTH; i++){
if( infile >> t[i][j] ){
switch(t[i][j]){
case 0://non solid
tiles[i][j].solid = false;
break;
case 1://solid
tiles[i][j].solid = true;
break;
case 2://dirt w/ grass
tiles[i][j].sprite.SetImage(tileImage[2]);
break;
case 3://topgrass
tiles[i][j].sprite.SetImage(tileImage[1]);
break;
case 4://dirt
tiles[i][j].sprite.SetImage(tileImage[0]);
break;
}
}
}
}
}
And the code that draws the tiles. Note that this problem has been occuring since before i implemented scrolling.
void Map::Draw(sf::RenderWindow& window){
int xPixel, yPixel; //screen coord for currenttile
int mapTileX, mapTileY;//current tile map coord
int startX = 0-(scroll_X)/TILESIZE; //start x
int smx = (startX+scroll_X)/TILESIZE; //start y
for( yPixel = 0-(scroll_Y % TILESIZE), mapTileY = (yPixel + scroll_Y)/TILESIZE; yPixel < SCREENHEIGHT; yPixel += TILESIZE){
for( xPixel = startX, mapTileX = smx; xPixel < SCREENWIDTH; xPixel+=TILESIZE){
if( tiles[mapTileX][mapTileY].sprite.GetImage() != NULL)
{
tiles[mapTileX][mapTileY].sprite.SetPosition(xPixel,yPixel);
window.Draw(tiles[mapTileX][mapTileY].sprite);
}
mapTileX++;
}
mapTileY++;
}
}

New Topic/Question
Reply



MultiQuote




|