-
I'm making a game in SFML 2.0 (I built the source myself) with Visual Studio 2012. I made a map system with vertexArrays, and it works nicely, everything is perfect in the game except a detail.
When walking around the map, I see some lines being displayed randomly for a very short amount of time, in random places, like a stuttering graphical bug. My friend said he also experienced this with his game so it made me think it's a SFML bug rather than a coding bug. Here's a screenshot bellow, you can see the line, it randomly appeared when I took the picture. Also in this picture I zoomed in the in-game camera.
-
Wild guess:
http://en.sfml-dev.org/forums/index.php?topic=11944.msg82959#msg82959
Texture coordinates have to be in middle of pixels so rect at 64,64 that is 32x32 has coords 64.5 64.5 95.5 95.5 not 64 64 96 96
-
It's probably caused by decimal coordinates. Round your view's position and everything should be ok.
-
It's probably caused by decimal coordinates. Round your view's position and everything should be ok.
I tried this, but it didn't work:
void camera::update()
{
const int halfDistanceX = view -> getCenter().x/2;
const int halfDistnaceY = view -> getCenter().y/2;
if(getCornerPoint().x <= 0 && getCornerPoint().y <= 0)
view -> setCenter((int)Player -> pos.x, (int)Player -> pos.y);
}
I could also try with roof() or floor()
-
Are your tiles located at decimal coordinates?
-
Are your tiles located at decimal coordinates?
Nope. Here's the code without the cast to int (Casting them to int was also a possibility, but failed)
// Set their positions
up_l_point.position = sf::Vector2f((int)(index*tile_size), (int)(index_y*tile_size));
up_r_point.position = sf::Vector2f((int)(index*tile_size + tile_size), (int)(index_y*tile_size));
down_r_point.position = sf::Vector2f((int)(index*tile_size + tile_size), (int)(index_y*tile_size + tile_size));
down_l_point.position = sf::Vector2f((int)(index*tile_size), (int)(index_y*tile_size + tile_size));
// Set their texture bounding box
up_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size, (j/tiles_per_row) * tile_size);
up_r_point.texCoords = sf::Vector2f((j%tiles_per_row * tile_size) + tile_size, (j/tiles_per_row) * tile_size);
down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size, (j/tiles_per_row * tile_size) + tile_size);
down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size, (j/tiles_per_row * tile_size) + tile_size);
-
Is the orange color part of the texture? Or is it coming from nowhere?
-
I experienced the same thing when I was working on my Tiled map loader. I'd tried rounding the position and the half pixel trick but the only work-around I found was to load the tile set as an image, then copy each tile to a texture, pushing it onto a vector each time so that the vector indices matched the tile IDs. Oh and this was happening when drawing the tiles as sprites too.
-
Is the orange color part of the texture? Or is it coming from nowhere?
It looks like it's part of the texture, because if it wasn't, I doubt I'd see random darkened pixels, that's my artistic style.
-
The question was if the orange pixels are pixels of next tile in your tilesheet or do they appear out of nowhere(which would be entirely different bug).
Also, try this:
// Set their texture bounding box
up_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row) * tile_siz +0.5f);
up_r_point.texCoords = sf::Vector2f((j%tiles_per_row * tile_size) + tile_size-0.5f, (j/tiles_per_row) * tile_size+0.5f);
down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size-0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
-
The question was if the orange pixels are pixels of next tile in your tilesheet or do they appear out of nowhere(which would be entirely different bug).
Also, try this:
// Set their texture bounding box
up_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row) * tile_siz +0.5f);
up_r_point.texCoords = sf::Vector2f((j%tiles_per_row * tile_size) + tile_size-0.5f, (j/tiles_per_row) * tile_size+0.5f);
down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size-0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
Yes the tile is before the grass tile, and the lines are always like that.
-
Frex's sollution seems to have worked, even though the map seems a bit more shaggy when walking around, at least there are no more lines.