Godot - Automated screenshots
22. January 2023
To publish a game to Apple App Store or Google Play Store, screenshots of the game are needed. For Android you need screenshots of mobile devices and tablets and for iOS you need a screenshot of each currently supported device.
With a little coding this boring and repetitive task can be automated. Of course, it depends a lot on the type of game and its mechanics, if its even possible to automate this task. But if it's a simple game like Ball2Box it will be easy.
How does it work
First, the resolutions of the devices are defined. The iPad screenshots can be reused as 7 inch and 10 inch tablet screenshots for Android.
const resolutions =
Then the paths of the scenes, that should be used for the screenshots, are defined.
const scenes = [ , , , , , , , , ]
The following function changes the scene to the ones we defined in the last step and hides the menu.
if scene != null: scene. var next_scene = scene = next_scene. # hide menu scene. .
With the following OS function call, we can change the resolution of the screen while the game is executed.
Then we get the texture data of the whole screen with the get_texture() Viewport function call. Since the image would be upside down, we flip it first and then we can save it on the file system.
var image = . . . image. image. + )
The whole code
Here, the whole code that iterates over the resolutions and scenes and takes the screenshots. It can be executed with the "Play custom scene" button on the right top corner of the Godot editor.
extends Spatial const resolutions = const scenes = [ , , , , , , , , ] var scene var scene_counter = 1 for scene in scenes: for resolution in resolutions. : OS. ) yield((). , ) # calculate x/y offset for bigger screens like iPads to center the screenshot var x = .x - . . .x) / 2 var y = .y - . . .y) / 2 var fullscreen = Rect2.x, resolutions. .y) var image = . . . image. image. + ) scene_counter += 1 . if scene != null: scene. var next_scene = scene = next_scene. # hide menu scene. .
This script could be used to create a tool for the Godot Asset Store, so it could be simply installed from there, but for my use case this is enough for now.
You can find this code and the whole game also on Github.