Android performance and camera issue? (SOLVED)

Hey Defold Community,

We are working on a mobile casual game since a few days now and discovered two problems when it comes to deploying to Android (and maybe also to other platforms).
The first problem refers to the camera which is as I understand also manipulated through my renderscript, which is almost the same as published here (except the helper class for transforming screen cordinates to world coordinates since it is not needed): https://github.com/britzl/publicexamples/tree/master/examples/fixed_aspect_ratio

After installing the built apk file and opening the app, I noticed that the screen on my smartphone (Samsung Galaxy S5) is filled as wished, while the screen on my friends smartphone (Samsung Galaxy S7) , which has a higher resolution (4k) but the SAME aspect ratio (16:9), is not completely filled with the level.

The second problem seems like a performance issue or a wrong configuration, since the game is lagging as the level progress increases. The weird thing about that is that the game only starts trembling on the S7, which should have much more CPU and GPU power.

We would appreciate help of any kind :slight_smile:
Thanks

André

The fixed_aspect_ratio render script that you are basing yours on mentions this in the readme:

“The area visible using the original screen size will always be visible, either centred if the window dimensions are larger, or zoomed out if either window width or height is smaller than the original size.”

This means that on your friends high resolution screen you’ll see the area defined in game.project and everything around it. It will not zoom in. You could modify the render script so that it zooms in if the screen resolution is higher than defined in game.project and zoom out if the screen resolution is smaller (this it already does).

If it’s a 4k screen it really has to have a pretty beefy GPU to be able to manage 60fps. Could you post a screen shot of how your game looks? Have you tried running the on-screen profiler, or even better, the web profiler against the phone?

2 Likes

Thank you @britzl for replying so fast.
I got the camera script working now and made sure that it will also zoom in if the screen resolution is higher than the defined one.
The reason for the choppy movement of the character and partially of the background on the Samsung Galaxy S7 actually was no performance issue since I scaled down the resolution to 720p instead 1080p and also tried decreasing the frame rate from 60 to 30. After finding out that this doesn’t solve the problem I did some more research and the issue turned out to be caused by insufficient precision in the vertex program of the sprite material as @Andreas_Jirenius says here:


So setting the precision from mediump to highp and then assigning the new material which includes the new vertex program to all sprites works.

Still, I have another question now.
How to get the modified fixed_aspect_ratio script to draw black bars / not render the areas around the aspect ratio region if the screen has a different aspect ratio than the game?

1 Like

You can do this by modifying the viewport using render.set_viewport so that it doesn’t cover the entire screen.

1 Like

Ok this worked fine, thanks :slight_smile:

I know this is an old thread, but it seemed more appropriate than starting a new one, because the problem is the fixed_aspect_ratio running on Android. My application uses both game objects and gui objects (often superimposed on the game objects).

I am using britzl’s fixed_aspect_ratio render script. All works fine in the simulator, resizing causes no problems, everything stays aligned.

When I move it to my Android (higher resolution in both dimensions) everything is very small and the GUI objects are larger and misaligned (the GUI objects do what I expect them to do, set farther from the center and larger).

I don’t really yet understand how render, camera, scaling fit in this framework, sorry. Still trying to catch up, but it feels like I am missing something simple and key.