While testing my
AnimatedSprite class i noticed something weird. First I though it was something on my end, but after playing around a little more I noticed, that the
sf::Sprite class has the same problem... (which makes sense, because I use the same code for calculating the texture coordinates)
Whenever I use the setTextureRect() member of a sprite and the left member is set to something other then the left border of the texture and I then rotate the sprite by 45 degrees the texture is offset by one pixel. Whether I use rotate or setRotation doesn't make a difference. This only happens with 45 or -45 or multiples of them (i.e.: 405, 765 etc.). This seems very weird to me, because the sf::Transform should not affect the texture coordinates, should it? It only affects the vertices, right?
Only thing I can think of, that might explain it, is that there is a float rounding error in updateTexCoords().
If the above makes no sense at all, then try this minimal example:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(500, 500), "Rotate Test");
sf::Texture texture;
texture.loadFromFile("Rotate.png");
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setPosition(200, 200);
sprite.setTextureRect(sf::IntRect(1, 1, 98, 98));
sprite.rotate(45);
sf::Event event;
while(window.isOpen())
{
while(window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
window.close();
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
with this image:
Rotated by 45° it looks like this:
The red boarder only appears when rotated by 45° any other angle works fine.
Can somebody else confirm this? I am using Windows 7 x64, a Geforce GTX 500 Ti, the latest source compiled with MinGW (gcc 4.7.2)