SFML community forums
Help => Graphics => Topic started by: Symphonym on August 28, 2012, 08:08:28 pm
-
So I decided to move my tile textures onto a spritesheet instead of having separate images. So I loaded the spritesheet texture to the sprite of my tile, set the textureRect of that sprite and this bug occurs.
I believe that the TextureRect is leaking, and here's why:
(http://i.imgur.com/94edv.png)
As I'm moving my character vertically, these spaces between tiles occasionally flickers (Took me ages to actually get one of these flickers on picture). For the record, this did NOT happen when I had separate textures. And I believe that the reason to why the lines are black/yellow is because my spritesheet looks like this:
(http://i.imgur.com/uANv7.png)
The tiles below the ground tiles are just there so I can distinguish the tiles easier, and no, I haven't finished the tile textures, that's why the same tile is looped all over the tiles on the spritesheet. Anyway, as you can see the edges around the tiles below the "ground" tiles are indeed yellow and black, which the flickering lines in the game are.
Is this a bug or am I doing something wrong? Should I create separate textures from the spritesheet and store them in a vector or such?
-
It's not a bug, this is the intended behaviour. It happens when your sprite is at decimal coordinates.
-
It might be an artifact resulting from OpenGL rasterization, like here (http://en.sfml-dev.org/forums/index.php?topic=4744). Does the problem disappear if you round the coordinates of sprite position and origin before drawing?
Laurent, it might be intended if you know the underlying mechanisms, but not from user perspective. One doesn't assume that pixels outside the texture rect are rendered. Is the behavior already mentioned somewhere in the documentation/tutorials or do you think it occurs too rarely?
-
Is the behavior already mentioned somewhere in the documentation/tutorials or do you think it occurs too rarely?
It is mentioned in the tutorials that don't exist yet ;D
-
Alright, if it's not a bug. What would be the optimal way of making a workaround? In other words, having a spritesheet, - the flickering
-
Try to align the sprite's position and origin to integral coordinates. Otherwise, leave a free pixel between the texture rects (the pixel has alpha value 0 or is masked with a color).
-
Try to align the sprite's position and origin to integral coordinates. Otherwise, leave a free pixel between the texture rects (the pixel has alpha value 0 or is masked with a color).
As I'm using very small pixel graphics I'm using a sf::View to scale things up. This also makes pixels much "bigger", so rounding off position to integers makes to sprite jump between different points etc, which I don't like at all. And leaving a free pixel on all sides of each tile (on the spritesheet) with the alpha value of 0 only gives the "lines" another color, this time the background color of the SFML window.
At the moment it feels like the only choice is to have sepearate images, but that will get very messy and just unorganized. Is there any other way to use spritesheets? :/
-
Don't scale the view then... It's anways not the best way to get such an effect. If (for some reason) you don't want to scale the original images to the needed size, then scale the sprite to the size you want. So you have a better precision while keeping the sprites scaled. ;)
-
Don't scale the view then... It's anways not the best way to get such an effect. If (for some reason) you don't want to scale the original images to the needed size, then scale the sprite to the size you want. So you have a better precision while keeping the sprites scaled. ;)
But still.. I don't really like having a small thing like sprite scaling deciding whether or not I use a spritesheet :s
-
And leaving a free pixel on all sides of each tile (on the spritesheet) with the alpha value of 0 only gives the "lines" another color, this time the background color of the SFML window.
Do you mean they get the window clear color, even when something has already been rendered before? That's strange, normally pixels with alpha value 0 shouldn't be rendered. Do you use a blend mode other than sf::BlendAlpha?
What happens if you use a color mask with sf::Image::createMaskFromColor() (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34)? You need to load the sf::Texture indirectly via sf::Image.