In GameMaker: Studio you can define various types of game
assets (or resources), like sprites, sounds, fonts and backgrounds
and each asset type has its own selection of codes for modifying
them, using them and moving them during your game. Many even have
functions that permit you to load and save these resources into
your game while it is running, but be warned though - Changing
resources easily leads to serious errors in your games! As such
it is a good idea to follow the following rules when changing
- Don't remove (delete) assets that are being used in the current room or being referenced directly in any room.
- If you have changed an included asset of your game (for example, you have replaced a sprite with a loaded image), when you restart the game using the game_restart() function, the changed assets are NOT restored to their original shape. In general, when you manipulate included assets you can no longer use the action or function to restart the game.
- Changing assets from a file can be a relatively slow process, so try not to use it mid game, but rather save it for moments in which any possible pause will not interrupt the game-play.
- Creating assets during game play (in particular sprites and background) easily uses large amount of memory, so be careful with this. For example, if you have a 32 frame 128x128 animated sprite and you decide to create 36 rotated copies of it you will use up 36x32x128x128x4 = 72 MB of memory! And, as these resources are not included in any of the pre-made texture pages that carry your original assets, they involve an extra page swap, which means many such assets can really slow things down.
- Make sure you delete the created assets you no longer need, otherwise you can end up with a memory leak which will slow down and eventually crash your game
In general, you should try not to change any resources during
game play, and it is better create and change the resources at the
beginning of the game or even at the beginning of a room.
Information on resources can be found in the following pages:
There are two extra functions related to the handling game assets. These functions can be used to find the unique index value for any given asset and the type of asset that it is, which opens the door to dynamically creating game assets from strings (for example):