ScreenWidth reporting wrong (larger) value?

I am trying to dynamically position a "Score" text element, on my hud (like "Score: 2300 pts"), at the horizontal center of the player's screen, under any resolution the game is played.
So I figured I'd set the Score.X to Screenwidth/2 at the beginning of the Layout.
I guess it is kind of working, but ScreenWidth is being reported wrong or something, because the Textbox (Score) is positioned not on the center of the game window but a bit to the left..

Also, on another case, I set the game character's Sprite to automatically bounce back whenever it hits the left or right borders of the game. But again, for this I am using Screenwidth (for the right border "X" position check). And again, the sprite goes past the right screen border for a bit (but ends up finally bouncing back).

So my guess is, ScreenWidth is reporting the wrong size.

Is this a known bug or something like that?
Or am I doing it wrong??

EDIT: It all works flawlessly when I go Fullscreen (F11) and reload the game (ScreenWidth is reported correctly). Is there a way to make it work in random-sized windowed mode?

:shock: 🙂 :o: :?: :?:
Make sure you are using the CLIENT width, not the width of the window, which will include borders.
Alternatively, did you use anchor behavior?

To get it to stay relative to a position on-screen
It's because you're using ScreenWidth instead of WindowWidth. The ScreenWidth is the size of the user's computer screen that's why on full screen it works. Windowwidth gives you the width of the HTML5 Canvas area. Hope that helps!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76448