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

Author Topic: sf::String width  (Read 3781 times)

0 Members and 3 Guests are viewing this topic.

kamac

  • Newbie
  • *
  • Posts: 19
    • View Profile
sf::String width
« on: November 10, 2011, 10:10:08 pm »
Hi.

I have read a topic about it, but no one explained how to do it <in code>.

There was wrote about using GetRect. Could i achieve width of my string in pixels with it?

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
sf::String width
« Reply #1 on: November 11, 2011, 12:35:33 am »
Well, there is really nothing to explain, use the GetRect method to retrieve the bounding rectangle of the text.
SFML 1.6:
Code: [Select]
sf::String string("hello");
float width = string.GetRect().GetWidth();


SFML 2.0:
Code: [Select]
sf::Text text("hello");
float width = text.GetRect().Width;

kamac

  • Newbie
  • *
  • Posts: 19
    • View Profile
sf::String width
« Reply #2 on: November 11, 2011, 09:53:32 am »
Oh. Thanks alot. I didn't recognize that GetRect() has sub functions  :?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::String width
« Reply #3 on: November 12, 2011, 11:13:44 am »
Quote from: "kamac"
I didn't recognize that GetRect() has sub functions  :?
There are no "sub functions" in C++. But GetRect() returns a sf::FloatRect object on which you can invoke further member functions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: