Note: This is for SFML 1.6.
So I have a sprite, which I want to be centered on the real position of the object it represents. I center it by calling the following:
m_Sprite.SetSubRect(sf::IntRect(0, 65, 65, 86));
m_Sprite.SetPosition(m_RealPosition.x - (m_Sprite.GetSize().x / 2), m_RealPosition.y - (m_Sprite.GetSize().y / 2));
m_Sprite.SetCenter(m_Sprite.GetSize().x / 2, m_Sprite.GetSize().y / 2);
This apparently doesn't work. I discovered this by creating an sf::Shape::Circle at the place represented by m_RealPosition, as such:
m_Marker = sf::Shape::Circle(m_RealPosition.x,
m_RealPosition.y,
5,
sf::Color(255, 0, 0));
The Sprite does its thing left of, and slightly above, the red circle it is supposed to be centered on. I rotate the Sprite very frequently using sf::Sprite::SetRotation, so I'm wondering if that is causing the problem.
I should note that the object in question inherets from an abstract class that has this in its constructor (the above code is being called every frame after construction, despite any inefficiency; m_Sprite from above is inherited from this abstract class):
m_Sprite.SetPosition(m_RealPosition.x - (m_Sprite.GetSize().x / 2),
m_RealPosition.y - (m_Sprite.GetSize().y / 2));
m_Sprite.SetCenter(m_Sprite.GetSize().x / 2,
m_Sprite.GetSize().y / 2);
So my question is basically this: are there any conflicts between SetCenter, SetRotation, SetPosition and SetSubRect that I should be aware of? Or can anyone else see what I can't? Why would my Sprite not be centering on m_RealPosition?
Thanks for any help anyone can offer!