I am making a PC game with HD(720p) and FullHD(1080p) resolutions. In windowed mode the value of ScreenWidth() and ScreenHeight() is the value of the window but it doesn’t work well because I use these values to center text in the screen and with the window near to the original resolution is correct. However if I resize the window smaller then the text is not centered.
It’s not related, at the moment although I think it’s not going well either, with ScreenWidth() and ScreenHeight(). It’s related with text width and height values, text.Width() and text.Height(), these values are not changing if the window is resized, always have the same values. BUG, isn´t it?
Are you updating the position of the text when you resize the window?
text.Width() is the width of the text object, not its position.
Sorry I have not fully explained the problem. Here is the code (I think I copied the code from this forum):
I know text.width () is not the position. I don’t need update the position of the text because gdevelop makes it automatically since all the graphics stuff is resizing correct except this text. I have other texts in the game resizing correct, the problem is with above code, maybe is wrong or maybe these variables, text.width () and text.height () are not updating correct.
I don’t create a code to resize window is the default gdevelop windowed mode.
Have you tried using anchor behavior?
You are changing the position only once when you create the object, hence your issue.
You mean that I need move the text to the center every frame because is not updated automatically, it is no sense. Anyway that is not the issue because I have made an experiment to test the bug:
CASE 1: this case is working ok. No matter you resize window the objects are centered.
CASE 2: this case has a timer of 5 seconds. If the window is resized before the timer is trigger, one time, then the objects are not correct centered, hence unwanted behavior.
CASE 3: this case has a timer of 5 seconds. If the window is resized before the timer is trigger, every frame, then the objects are not correct centered, hence unwanted behavior.
So the bug is screenwidth() and screenheight() values are not updated and maybe the same with text.width() and text.height()
I fixed the problem replacing screenwidth() and screenheight() for SceneWindowWidth() and SceneWindowHeight()
Anyway I don’t understand why it doesn’t work with screenwidth() and screenheight() since in debug mode they are updating correctly their number values when I resize the window, however visually not the same. Is then a bug?
If you want your text position to always adapt, then yes, update it every frame.
Maybe a bug, maybe a limitation of the preview, not sure.