SFML community forums

Help => Graphics => Topic started by: Glocke on March 21, 2015, 05:46:57 pm

Title: [SOLVED] Zooming View: Scale position but not size of Drawable
Post by: Glocke on March 21, 2015, 05:46:57 pm
Hi, I'm using two views: Scene and GUI view. Both are resized if the window gets resized. Additionally, the scene view is moved and zoomed by the players' movement. Now I'd like to draw some "damage labels" (those flying text labels with e.g. damage values). I don't know which view to use:

Using the scene view's position won't work, because: If the scene is zoomed, the transformation (that is applied to all positions while drawing) will zoom the position and dimension of any drawable. Those damage labels' positions should be scaled but not the labels theirselves.

Any suggestions? Or does anyone have an idea how to solve the entire problem else? Doing the calculations (translation and scaling to the damage labels positions) on my own should work - but I hope there's another solution :)

Kind regards
Glocke
Title: Re: Zooming View: Scale position but not size of Drawable
Post by: Laurent on March 21, 2015, 06:57:43 pm
Use the GUI view, but map the position from scene view to GUI view:

// 1. map from scene coordinates to window coordinates
sf::Vector2i positionInWindow = window.mapCoordsToPixel(position, sceneView);

// 2. map from window coordinates to GUI coordinates
sf::Vector2f positionInGuiView = window.mapPixelToCoords(positionInWindow, guiView);
Title: Re: Zooming View: Scale position but not size of Drawable
Post by: Glocke on March 21, 2015, 07:04:29 pm
// 1. map from scene coordinates to window coordinates
sf::Vector2i positionInWindow = window.mapCoordsToPixel(position, sceneView);

// 2. map from window coordinates to GUI coordinates
sf::Vector2f positionInGuiView = window.mapPixelToCoords(positionInWindow, guiView);
Great! That was exactly what I was looking for. Thanks a lot - it works just perfect :)