Handling multiple resolutions (SOLVED)

Hi guys,

I am new to the forum and the Defold engine in general, currently I am working on a mobile game, and wanted to handle the problem with the multiple device resolutions.

I searched here in the forum, and found some examples from @britzl.

Currently I am using his defold-orthographic scripts, but I think that maybe I haven’t configured them properly.

I created a sample project where I positioned 4 objects in every corner of the screen and 1 object in the middle. My project resolution is 480x720.
When I run the game on my PC the objects are position perfectly even on fullscreen, but when I run it on my phone with FULL HD resolution, the object are not lined with the bottom and top of the game.

  • These are the screenshots from my PC.


  • This is the screenshot from my phone.

I am not very good with the whole render stuff and if you guys can help me out I will be very grateful. Sorry if I post yet another thread about multiple resolutions problem.

2 Likes

The render script will allow you to define how your game is rendered. You can have the render script stretch your game to ensure that it fits the entire screen. This can make objects look stretched in one or the other direction, depending on if the aspect ratio of the screen differs from what you have in game.project. This is what the default render script does and what happens if you use my Orthographic Camera API and the render script that comes along with the extension and select DEFAULT as projection:

Projection: defold-orthographic/orthographic/camera.lua at master · britzl/defold-orthographic · GitHub

Now, the above behaviour might work for some games, but not for all. Perhaps you want to always zoom out to always show what would fit in the area defined in game.project regardless of the screen dimensions? This is what FIXED does:

Projection: defold-orthographic/orthographic/render/orthographic.render_script at master · britzl/defold-orthographic · GitHub

If you don’t want it to zoom but maintain a fixed aspect ratio instead of the default stretch then set it to FIXED_NOZOOM: defold-orthographic/orthographic/render/orthographic.render_script at master · britzl/defold-orthographic · GitHub

Finally there’s also support for fixed zoom values such as x2 (FIXED_ZOOM_2), x3, x4 etc: defold-orthographic/orthographic/render/orthographic.render_script at master · britzl/defold-orthographic · GitHub

Back to your original problem. You want the game objects (logos) to not stretch but anchor to the bottom and top of the screen regardless of screen resolution and aspect ratio? That is something that no render script can achieve. The GUI system can however anchor nodes in the way you want.

5 Likes

Thanks for your in detail explanation about the render script and your lib. I am unsure just how to position my objects so that they will look good. I don’t want to position something let’s say 30 px above the bottom line and to look good on my devices but for some other phones to be 60 px above the bottom line.

I haven’t made games that got released and I am unsure what is the right way to position everything in the game so it will look the same no matter the device. I’ve played different mobile games and there everything is position perfectly and looks the same.

If you @britzl or someone else could just point me in some direction I will be thankful :slight_smile:

What kind of game are you creating? What type of objects do you wish to anchor to certain positions? UI elements?

1 Like

I am currently working on a simple board game, but after your previous post I looked at my game and realised that the anchored parts are my GUI so I added them to the GUI.

As for the rest of the objects I just repositioned the camera object and I think that now it looks good.

Thank you again.

3 Likes

It seems what I understand your question.
In hamster I solved this problem very easy: the game has no GO elements in corners :wink:
Else it was be as pain, zoom factor+aspect ratio + perspective camera (not linear formula for translate screen to world coordinates )

2 Likes

Yes I was trying to do this with GOs but I failed :smiley:

Then I realised that the objects were my health bars and some other stuff that are all part of the GUI
if you think about it. And now I anchored them to the corners and it actually looks good.

Soon when I have a demo to share I will definitely will create a thread about it. :yum:

3 Likes