This is my first time posting on this forum. Please let me know if any further information is needed.
I’m currently developing a 2D game for iOS and Android. I was previously using the “Starly” library to manage a fixed aspect ratio and a camera that follows the player.
However, after a recent Defold update, it seems Starly is no longer working correctly, so I am trying to switch to Defold’s built-in features to achieve the same results.
I have a few questions about this:
Is using the built-in camera and render script features the standard approach for a fixed aspect ratio and a player-following camera? Or is there a simpler, or more recommended, modern asset for this?
I want to display a full-screen background image that exactly fits the device’s display size. This background should be static and not be affected by the camera’s movement. What would be the best way to implement this?
When the game is run on a screen with a different aspect ratio, I want to show black bars on the sides (letterboxing/pillarboxing) and ensure that no game objects are rendered in these black areas. How can I achieve this effect?
With the recent improvements to the camera I would definitely try this approach first! There’s less and less need for camera extensions to be honest.
There’s at least two solutions:
Create a gui component with a full screen image node (box node). Make a copy of the default gui.material and change the material predicate to something like “background”. Then make a copy of the default render script and draw the “background” predicate before you draw any sprites
Attach a sprite component to the same game object as the camera component, make sure the z values is behind any of your other objetcts.
This may sound silly, but honestly the easiest way to do this is to add a gui component with big fat black boxes around the edges to cover any additional area outside of the default view. The other solution is to change the viewport in the render script.
I was able to successfully implement the fixed, full-screen background image based on your advice. It’s working perfectly in my tests.
This was a huge help. Thank you so much