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

Author Topic: [SOLVED] SFML 2 Window resize & view resize  (Read 2903 times)

0 Members and 1 Guest are viewing this topic.

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
[SOLVED] SFML 2 Window resize & view resize
« on: August 20, 2011, 01:06:05 pm »
Hi!

I've got an issue. When I resize the game window, and all the views including the default view, the text I draw on the default view changes it's position, no matter if I reposition it with "SetPosition(20.f, 20.f);", or not.

The truncated code is:

Code: [Select]
       // Process events
        sf::Event Event;
        while (window.PollEvent(Event))
        {
            if (Event.Type == sf::Event::Resized)
            {
                defaultCamera.SetSize(Event.Size.Width, Event.Size.Height);
                window.SetView(defaultCamera); // ... Just trying to make it work
                FPSText.SetPosition(20.f, 20.f); // ... Here too
            }
        }


See two screenshots of the resize:





Am I missing something?

Thanks for your answers,
easy

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
[SOLVED] SFML 2 Window resize & view resize
« Reply #1 on: August 20, 2011, 04:25:29 pm »
Answering my own question for that anybody can find this solution:

Code: [Select]
FPSText.SetPosition(window.ConvertCoords(20, 20, defaultCamera));

And the reason behind it is:
Code: [Select]
   ////////////////////////////////////////////////////////////
    /// \brief Convert a point from target coordinates to view coordinates
    ///
    /// Initially, a unit of the 2D world matches a pixel of the
    /// render target. But if you define a custom view, this
    /// assertion is not true anymore, ie. a point located at
    /// (10, 50) in your render target (for example a window) may
    /// map to the point (150, 75) in your 2D world -- for example
    /// if the view is translated by (140, 25).
    ///
    /// For render windows, this function is typically used to find
    /// which point (or object) is located below the mouse cursor.
    ///
    /// This version uses a custom view for calculations, see the other
    /// overload of the function to use the current view of the render
    /// target.
    ///
    /// \param x    X coordinate of the point to convert, relative to the render target
    /// \param y    Y coordinate of the point to convert, relative to the render target
    /// \param view The view to use for converting the point
    ///
    /// \return The converted point, in "world" units
    ///
    ////////////////////////////////////////////////////////////
    Vector2f ConvertCoords(unsigned int x, unsigned int y, const View& view) const;