Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Zooming View: Scale position but not size of Drawable  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
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:
  • If I use the GUI view, then moving the scene (e.g. by moving the player) would move all damage labels - they would chase the players ... not good! The labels should stay at their initial (map) position but flying upwards (along -y axis)
  • If I use the Scene view, the damage labels are also scaled referring to the zoom that is applied to the view. But zooming the labels isn't what I want: I'd like to keep their size constant in both cases: scene zoomed or not.

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
« Last Edit: March 21, 2015, 07:04:44 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Zooming View: Scale position but not size of Drawable
« Reply #1 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);
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Zooming View: Scale position but not size of Drawable
« Reply #2 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 :)
Current project: Racod's Lair - Rogue-inspired Coop Action RPG