SFML community forums
Help => Graphics => Topic started by: MickeyKnox on June 07, 2011, 01:43:53 pm
-
I want to access the corner Points of a Sprite, but i can't
find a suitable method. Is it possible to get these points directly?
-
Not directly, but like this:
leftUpperCorner = position - origin;
rightLowerCorner = position - origin + size;
By the way, I should really add methods for direct access of border coordinates to my Thor library. In fact, I had implemented them, but removed them before 1.0 because they weren't mature enough.
-
The points in local coordinates are:
- (0, 0)
- (0, sprite.GetSubRect().GetHeight())
- (sprite.GetSubRect().GetWidth(), 0)
- (sprite.GetSubRect().GetWidth(), sprite.GetSubRect().GetHeight())
The points in global coordinates are:
- sprite.TransformToGlobal(px)
where px is one of the local points.
-
Laurent, your approach is better since it takes rotation and scale into account. Apparently, I was right with the "not mature" ;)
But this raises another question: How would one implement something like
float GetRight(const sf::Sprite& sprite);
? There is no meaningful way because the right edge may be rotated. There are however still enough cases where a sprite is axis-aligned... Hm, I'll probably just wait with this stuff, there are more important tasks anyway :)
-
Well, my sprites may have an arbitrary rotation. Thus, in my case it is not
that easy. So i guess i have to do some trigonometrics?
By the way, what i want to do is to draw a rectangle (with sf::Shape)
around the sprite, when the user selects it. If there is a better way
to archive this, please let me know.
-
Another approach i can think of is to have another image/sprite with just
the rectangle, and the rest of it transparent. Then i keep the position and
rotation of the two synchronized and only draw the second sprite, when
the user selects that unit.
Which approach is better in your opinion?
-
Well, my sprites may have an arbitrary rotation. Thus, in my case it is not
that easy. So i guess i have to do some trigonometrics?
No, that should work the way Laurent explained. It is just my approach that doesn't cope with rotation :D
By the way, what i want to do is to draw a rectangle (with sf::Shape)
around the sprite, when the user selects it. If there is a better way
to archive this, please let me know.
I think this is a good way, better than creating a separate sprite with only a border. The sf::Shape rectangle can be rotated and scaled the same way as the original sf::Sprite in order to align it correctly.
-
ok, thank you guys ~