2 Replies - 1170 Views - Last Post: 07 October 2012 - 06:06 PM Rate Topic: -----

#1 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

SFML tile drawing tiles overlap

Posted 07 October 2012 - 11:14 AM

Hello,

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++;
	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: SFML tile drawing tiles overlap

#2 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 801
  • View blog
  • Posts: 2,357
  • Joined: 20-March 10

Re: SFML tile drawing tiles overlap

Posted 07 October 2012 - 05:15 PM

Hi,

Try turning off smoothing ie

on your sprite images ie...

image.SetSmooth(false);

This will turn off the automatic blending function in sfml.


Regards

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#3 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

Re: SFML tile drawing tiles overlap

Posted 07 October 2012 - 06:06 PM

View Postsnoopy11, on 07 October 2012 - 05:15 PM, said:

Hi,

Try turning off smoothing ie

on your sprite images ie...

image.SetSmooth(false);

This will turn off the automatic blending function in sfml.


Regards

Snoopy.



I love you so much dude
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1