Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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: :smile: :eek:: :?: :?:
 
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!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top