SFML community forums

Help => Graphics => Topic started by: tymofey on September 12, 2011, 08:33:30 pm

Title: RenderTarget::ConvertCoords backwards
Post by: tymofey on September 12, 2011, 08:33:30 pm
I wanted to draw some text in RenderWindow that would be positioned near a sprite, like a label or tag always moving along with the sprite, attached to some point of it and not rotating or scaling regardless of sprite's transformations. And I was really surprised to not find a complementary function to ConvertCoords, that would convert world coordinates to screen coordinates. I believe this to be a frequently occuring task and i guess it is only reasonable to add such functionality to RenderTarget
Title: RenderTarget::ConvertCoords backwards
Post by: sbroadfoot90 on September 25, 2011, 01:19:05 am
I wanted to draw some text in RenderWindow that would be positioned near a sprite, like a label or tag always moving along with the sprite, attached to some point of it and not rotating or scaling regardless of sprite's transformations. And I was really surprised to not find a complementary function to ConvertCoords, that would convert world coordinates to screen coordinates. I believe this to be a frequently occuring task and i guess it is only reasonable to add such functionality to RenderTarget


The ConvertCoords(x, y, view = NULL) function takes x and y global coordinates and transforms them into view coordinates given the current view attached to the render window.

I think the functionality you wanted was to get the sprite's coordinates in terms of where it will be drawn on the screen. It wouldn't make much sense to have a function for sprite saying Sprite::ConvertCoords(view), meaning, you pass in a view and get it's coordinates out in terms of the view. (You could call it, GetPositionInView or something.

What you really want to do is


Code: [Select]

Window.ConvertCoords(Sprite.GetX(), Sprite.GetY());


as the window will have the view already attached to it.