Hey peeps!
Just started to work with SFML(.NET) a few weeks ago by porting my game from MonoGame to it.
So, I tried to port the dynamic text rendering method to SFML and when using getGlobalBounds() for a Text object I get a Rectangle with the right X and Y coordinates but with Zero for the width and height.
Here is the relevant code:
FloatRect rectangle
= new FloatRect
(SomeXCoordinate, SomeYCoordinate, SomeWidth, SomeHeight
);_text
= new Text
(text, FontManager
.KingthingsFoundation,
50);_text
.Position = new Vector2f
(rectangle
.Left, rectangle
.Top);uint currentDotSize
= 49;FloatRect stringSize
= _text
.GetGlobalBounds();Console
.WriteLine(stringSize
);while((stringSize
.Width > rectangle
.Width || stringSize
.Height > rectangle
.Height) && currentDotSize
>= 0) { _text
= new Text
(text, FontManager
.KingthingsFoundation, currentDotSize
); _text
.Position = new Vector2f
(rectangle
.Left, rectangle
.Top); currentDotSize
--; stringSize
= _text
.GetGlobalBounds();}Where "text" is a specific String and the "rectangle" object is a Rectangle the text should fit in.
Now, as i said, on the line "Console.WriteLine(stringSize);" it prints out:
"[FloatRect] Left(SomeXCoordinate) Top(SomeYCoordinate) Width(0) Height(0)"
And therefore it doesn't even enter the while-loop.
I just can't wrap my head around why this is happening. Help would be very appreciated!
EDIT: Might also be worth noting that this is the only code in the method and that "text", the values for "rectangle" and the font are the only outside variables accessed.
"_text" is just a "private Text _text" which hasn't been touched before.