Screen width and height

I think there was a thread about this, but I am just wondering how do I know the screen width, height when it is constantly changing.

Let me argue that the screen size in microStudio is more consistent than in most other 2D game engines :-) ... and actually never changing! But I understand how puzzling it can be if you were used to working with physical screen coordinates before.

Consider that people who will play your game will have different screen resolutions, 1024x768, HD, full HD, full HD+, 4K, 3440x1440, whatever... In many 2D engines, if you want to support any screen resolution, you will have to deal with that all by yourself: compute the correct scaling ratio for all your sprites, figure out the coordinates of the center of the screen...

microStudio takes care of all this for you and pre-scales the screen space, ensuring that your game will look the same on any screen. There are actually two cases:

  1. Screen is in landscape mode (width>height): the screen height is fixed to 200, ranging from -100 (bottom of the screen) to +100 (top of the screen)
  2. Screen is in portrait mode (height>width): the screen width is fixed to 200, ranging from -100 (left hand side) to +100 (right hand side)

This way, if you choose to display a sprite with a size of 20x20 (screen.drawSprite("mysprite",x,y,20,20)), it will always look of the same size, relatively to the size to the full game window. Consider the game below, launch it and resize the window, even to extremely flat landscape mode or very thin portrait mode, you will see that it can be played on really any screen... and we didn't even have to care about it when writing the code:


Of course it cannot be all perfect:

  • while it is really easy to center things, if you want to display stuff attached to the borders of the screen, you will often have to use screen.width or screen.height to compute a correct position.
  • not every game can be played in both landscape and portrait modes, of course! In your project settings, you can set whether your game must be played in portrait or landscape mode ; you can even set a forced a screen ratio whenever necessary.

The coordinates system is explained in the documentation, section Function Reference / Display (screen)

Thank you this is helpful as I didn't know I can force a screen resolution.

Is it possible to be signaled when the screen size has changed as a result of being resized? Or do I regularly check the current screen object values for that? My game needs to redraw the screen if it has changed, otherwise it goes black when resized.


Checking the screen values for changes does work quite well.

Post a reply



Validate your e-mail address to participate in the community