SFML community forums
Help => Graphics => Topic started by: gokaysatir on March 09, 2013, 04:05:04 pm
-
Hi,
I am trying to display text using SFML 2.0.
Text is displayed very nice at first, but while resizing i recreate the text object and use this code for scaling:
sf::Text crd; // Create text object..
crd.setFont(My_Fonts::types[0]); // Select font..
crd.setString("Sample Text"); // Set string..
crd.setOrigin(0, 0);
crd.setPosition(10* 1000 / width, 400); // Set position using width variable so it remains at the same point after resizing.. I couldn't find a way to make y point remain unchanged, (400 * 1000/height) doesn't work..
// Variable 1000 is an experimental value i use to specify the gap between text and window border..
crd.setCharacterSize(12U);
crd.setColor(sf::Color(0,0,0));
crd.scale(height/width, 1.0f); // Set scale x according to y and leave y untouched..
texts.push_back(crd); // Put it into an array..
With this code i can save x scale but the y scale is deformed and after resizing the text is displayed stretched.
I hope i could explain my problem. Thanks in advance:)
-
In order to make my code more clear i can give an example:
When the window size.x = 500;
The position.x = 10 * (1000/500) = 20;
And when the window size.x = 1000;
x position gets the value "10".
So if "20" in 500.x size equals 20 pixels, "10" in 1000.x size equals 20 pixels too. The position is safe.
I couldn't use this approach for y coordinate. Also couldn't prevent the deformation in y scale.
Sorry for my bad English :-[
-
You should rather adjust the sf::View of the window, than trying to scale everything manually (e.g. see here (https://github.com/eXpl0it3r/TileMapCreator/blob/master/src/Application.cpp#L93)).
-
Hi,
You're right ::) I tried to reset view variables after resizing and it's ok now. Text is displayed perfect again.
Thank you :)