Shin's site
_
Home
GB Studio resources

This page
_
Top
Replacing On Update scripts
Improving On Update scripts
Using intelligent game design
Using CGB mode
More resources
Title
_
GB Studio 3.1+ Tutorial.
Reducing slowdown and improving performance.
Last updated 3/2/2023.

Introduction
_
This tutorial was written for GB Studio 3.1.0 and is subject to change! A video version of this tutorial is available here:



One of the most common complaints from new GB Studio users is that their game is lagging or there is severe slowdown. Even for advanced users, getting your game to run nicely can be difficult. While the Game Boy isn’t a powerhouse, there are several strategies you can employ to increase your game’s performance and reduce slowdown. They mostly involve reducing the number of scripts that are run every single frame. This tutorial will cover the following four strategies:

Replacing On Update scripts
_
On Update scripts are the least performance friendly type of script, as they run every single frame, or 60 times a second at full speed. That is a lot for the 30 year old Game Boy CPU to handle. In my experience, On Update scripts are the main cause of slowdown in GB Studio games. So, when appropriate, try to use On Hit or On Interact scripts that only run once, instead of On Update scripts that run 60 times a second. Does your On Update script need to run all the time, or just when a specific event occurs? If it doesn’t need to run every single frame, you may be able to replace it with another type of script.

A typical example of a wasteful On Update script is an On Update script that controls a health bar actor. In this example, the health bar actor’s graphics are updated every frame using its On Update script. You can see that the script itself is just a simple switch that changes the health bar’s graphics depending on the health variable, but when it runs 60 times a second in an On Update script, it can have a significant impact on performance. The health bar’s graphics do not need to be updated 60 times a second, rather they only need to be updated when the health variable changes. Instead of using an On Update script, we can move the same behaviour to one of the On Hit scripts that is called just once when the player is hit. In this example, when the player is hit, their health is reduced by one, and then the health bar’s graphics are updated to reflect this. This means the script is only run once when it is required, and will have a negligible impact on performance. You could include this script in either the player’s On Hit scripts, or the enemy’s On Hit scripts. You would also need to add a script to the scene’s On Init script to set the health bar’s graphic once before the scene starts.

Improving On Update scripts
_
Of course, there are many scenarios where using an On Update script is more appropriate or even necessary. In these scenarios, we want to design the On Update script in the most performance friendly way possible, which is the focus of this next strategy. To improve the performance of your On Update scripts, try the following:

Using intelligent game design
_
When initially designing your game, you should design your game with the knowledge that the Game Boy is not a powerful console, and that GB Studio games have less than optimal performance to begin with. Come up with an idea that fits the Game Boy and GB Studio, instead of trying to force an ambitious idea that doesn’t fit. This means designing the game with limited actors and On Update scripts per scene. Look at Game Boy games published by Nintendo or other GB Studio games to get an idea of what may be realistic. There's a reason that the Game Boy library was overrun with puzzle games and RPGs, as the gameplay is simple, slow and performance friendly. Even a huge action adventure like Link’s Awakening doesn’t show more than 3 or 4 actors on the screen at once to optimise performance. You may realise your game is overly ambitious part way through development. Don’t be afraid to scale back mid-development, whether that means cutting some features or restructuring altogether. It can be difficult to predict what GB Studio is capable of, especially for your first few games, so try to adapt as you go.

Using CGB mode
_
Enable CGB mode to instantly improve your performance. The Game Boy Color has better hardware than the original Game Boy, and its CPU can run at twice the speed. In other words, it can basically do twice as much per frame before slowdown occurs, meaning On Update scripts can be much longer. You can also have more actors on screen before slowdown becomes as noticeable. To take advantage of this performance boost, tick the 'Enable Color Mode' box in your project settings. The performance boost will only apply when playing on CGB or GBA, not on DMG. It should also apply in most emulators.

More resources
_
Now you can improve the performance of your GB Studio games. The other tutorials on this site are designed with performance in mind. Take a look at the general structure of the scripts in other tutorials. It might help you to write your own efficient scripts.

If you have any queries about the tutorial contents (NOT general questions about GB Studio) contact me via my Twitter. Constructive feedback is appreciated.