Speed games up
From YoYoGames Wiki
Speeding games up is very important in big games.
Contents |
Resource Management
Delete unneeded resources (like sounds, graphics, etc.) so they don't take up memory. In addition, load resources externally whenever possible, using *_replace() functions (sprite_replace(), background_replace(), etc.).
Deactivating Instances
Deactivating instances will speed up the game because objects outside of the view won't take up processing time. No events will be performed for them, nor will a sprite be drawn. At that point, the instances act as if they don't exist; It's very easy to do this. Simply use the code below.
Code
instance_deactivate_all(true) instance_activate_region(view_xview[0],view_yview[0],view_wview[0],view_hview[0],false)
Check the GM manual under "deactivating instances" for the syntax of all instance (de)activation functions.
See also: GML_Functions:_Deactivating_Instances
Sprites
Using one sprite per object is very useful. Using two self-declared variables called animStart, and animEnd will work. animStart represents the starting image_index, and animEnd represents the ending image_index. You'll be checking whether the image_index is smaller/bigger than animStart/animEnd then changing image_index accordingly, to only show the parts of the sprite's animation that correspond to what the sprite should be doing.
Tiles
Use tiles whenever possible, especially to replace objects when forming ground. Make an invisible object, call it objBlock, give it a black square/rectangle sprite, and after using tiles to design your level, use this new object to "outline" your walls so the other objects can't go through the tiles.
Slow functions
This is a list of functions in GM that are considered slow and thus able to slow your game down.
- execute_string() - Try to avoid calling this function a lot. Only the initial overhead is slow, the code itself is executed just as fast as normal code. (see also execute_file())
- variable_*() functions - These functions are roughly 50 times as slow as normal variable assignment and comparison.
- draw_text() - drawing text is much slower then drawing sprites or surfaces, so if possible, draw the text only once onto a sprite or surface and then draw that item each step.
- draw_getpixel() Returns the color of the position given. Will slow down game if not used sparingly.

