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

Author Topic: sf::Text shift  (Read 1608 times)

0 Members and 1 Guest are viewing this topic.

Romex

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::Text shift
« on: January 14, 2013, 11:07:45 am »
Hello!
#include <SFML/system.hpp>
#include <SFML/graphics.hpp>
int main()
{
        sf::Font font;
        font.loadFromFile("fallout_decayed.ttf");

        sf::Text text("EXAMPLE",font, 50 );
        text.setPosition( 100, 100 );
        text.setColor(sf::Color::Red);

        sf::RectangleShape rectangle( sf::Vector2f( text.getGlobalBounds().width, text.getGlobalBounds().height )  );
        rectangle.setPosition(100,100);
       
        sf::RenderWindow window( sf::VideoMode(400, 300), "EXAMPLE" );

        while( window.isOpen() )
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                window.clear();
                window.draw( rectangle );
                window.draw(text);
                window.display();
        }
        return 0;      
}
 
Why is the text shifted from its position?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text shift
« Reply #1 on: January 14, 2013, 11:11:52 am »
rectangle.setPosition(text.getGlobalBounds().left, text.getGlobalBounds().top);

instead of

rectangle.setPosition(100,100);
Laurent Gomila - SFML developer

Romex

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text shift
« Reply #2 on: January 14, 2013, 11:23:11 am »
Thanks!