In my opinion the most important aspect of game programming is keeping the game optimized. Nobody likes a laggy game. Using speed techniques the game will run smoother, and allow more calculating and more drawing on the screen.
Technique 1Keep culling on. This is done by: d3d_set_culling(1). Keep culling on will remove all backface drawing, and thus increasing the drawing performance
100%. The only trouble is drawing the faces in the right order. This will take some getting used to.
Technique 2Execute as little code as possible. Often things do not need to be checked. My advice is to have a controller object that keeps track of the most important things of gameplay.
Technique 3 Executing background_get_texture(...) every step is a big waste of memory, so define all textures only once. Do this in the [Create Event] of the controller object as follows:
- Code:
-
tex[1] = background_get_texture(bg_tex1);
tex[2] = background_get_texture(bg_tex2);
tex[3] = background_get_texture(bg_tex3);
etc...
Now, when drawing the texture, simply put tex[texture_index] in the texture argument. Do not define all textures in each object that uses them, but load the texture from the controller object. For instance, say object_1 wants to load tex[2] from the controller object. The code will be this for the texture argument:
- Code:
-
obj_controller.tex[2]
Technique 4Always use models. When using models Gamemaker only needs to draw them. When using d3d_draw... functions Gamemaker needs to construct the model first, and then draw it on the screen. This will cause a big loss of drawing performance. Also, keep in mind that the lesser polygons in your model, the lesser they consume.
Technique 5Just like the textures, define all models only once. Load them from a controller object just like the textures.
Technique 6Caution: This technique only works if you know exactly what you're doing; otherwise it will lower performance.
Generate terrain to big models. For example, if you have a terrain with grass and ground, generate all grass to one big grass model, and generate all ground to one big ground model.
Technique 7Make a draw distance system. Objects at a certain distance won't be drawn. You could do something like this in the
[Draw Event]:
- Code:
-
if point_distance(x,y,global.camera_x,global.camera_y) < 128
{
//draw
}
An other technique is to set and unset the visibility of objects. You could have an alarm run all the time to keep checking it. Be sure to set the alarm in the [Create Event] to start running the alarm! This is for example the
[Alarm 0 Event]:
- Code:
-
alarm[0] = 3; //keep the alarm running
with (all)
{
if point_distance(x,y,global.camera_x,global.camera_y) < 128
visible = 1;
else
visible = 0;
}
obj_controller.visible = 1; //make sure the controller remains visible.
If you have a lot of objects to check just set the alarm to a greater value to decrease the speed of checking.
This will greatly increase performance if you do it right.
Technique 8This isn't really a technique, and you most likely know this, but when running the game close all unnecessary programs. Closing downloads, media players and even internet explorer will increase the runtime of your game.
Technique 9An important aspect of RAM usage is the loading of external files. Often unused textures/models/sounds are kept in the RAM memory when they aren't needed. This is obviously wasted memory. Try to load resources when you need them, and get rid of them when you don't.
I hope it helps