SFML community forums
Help => Graphics => Topic started by: Kingdom of Fish on March 04, 2008, 02:09:15 pm
-
How do i get the actual width of a text, lets say if i want to put the text in the center of the screen i get the rect from the font object divide the width by two and put that in the center but the text seem to be a little off. If you dont get what i mean i'll post screens but i have non atm.
-
Which version of SFML are you using ? If it's not the current SVN one, then forget about it : fonts and text rendering have been completely redone ;)
Otherwise, screenshots could help.
-
I use the SVN version and the screen looks like this:
(http://img187.imageshack.us/img187/2100/screenshotspinitmfjo4.th.png) (http://img187.imageshack.us/my.php?image=screenshotspinitmfjo4.png)
All those texts should be centered in the screen and as you can see they are not.
-
Can you show us the corresponding code (should be very short) ?
-
This is the code i use to place each of the options:
void MenuScene::addOption(string opt, float offset)
{
sf::String* s = new sf::String(opt);
s->SetSize(40);
float width = s->GetRect().GetWidth();
s->SetCenter(width/2.0, 20);
s->SetPosition(400, nextOption+offset);
s->SetColor(sf::Color::Red);
nextOption += (60+offset);
mOptions.push_back(s);
}
Since i haven't really got the hang of fonts i dont use it just accept the default.
-
There was a bug in the sf::String rendering. It's now fixed.
Thanks for your help :)
-
oh, sweet :)