ScreenWidth is the WindowSize or GameSize?

I have a two characters that oscillate left and right across the screen—from 0 to ScreenWidth().

  • Everything works fine until you resize the screen.
  • As you can see from the screencast below, it appears that on resize, ScreenSize() gets updated to the new window size.
  • That’s surprising because Game resolution resize mode is set to “No changes to the game size”
  • I expected that ScreenWidth() would be the same no matter the window size
  • Or is there another method to get the “game” size (an invariant that stays the same no matter the size of the window)?

It works fine on initial preview size:

lena1

Doesn’t work on resize

lena2

Running is controlled by the runDirection

  • runDirection=1 => run right
  • runDirection=0 => run in place
  • runDirection=-1 => run left

The important thing is that changes to runDirection are controlled by where they are on the screen. When they reach the edge of the right screen, they stop. And then when they reach the edge of the left screen, they also stop.


UPDATE: looks like what I wanted was SceneWindowWidth:

  • ScreenWidth - the window width?
  • SceneWindowWidth - the width of the scene
1 Like

Hello, I think changing from ScreenWidth to SceneWindowWidth will solve the problem. Also one simple solution is to check the Update Resolution, in the Project properties. (but this solution requires to change the Game Resolution Mode from No changes to Change the width to fit the screen)

A Checked Update Resolution results to this
image
check

An Unchecked Update Resolution results to this
image
uncheck

Note: This affects the quality of your sprites (images become blurry)

In addition, here are some descriptions that is related to screen thingy

(The image was from the wiki page, Expressions reference [GDevelop wiki])

Hope this helps :smiley:

4 Likes