To start programming in GameMaker you have to know some importants codes to make a complete game, in this tutorial i will teach you the most important variables and functions.
First of all, GameMaker has some built-in variables ready to use in games these variables are :
Some global variable :
The global variables can be used normally in any object.
-score : this will store the score value.
-health : this is for the player's health.
-lives : this is for number of player's lives.
Some local variables :
The local variables are just for the object, for exemple if we have two objects : the player and the ennemy, the variables of the player like (x,y....) are not the same of the ennemy.
And if you want to modify a variable of the player but in the ennemy object you have that it is for the player or any other object by writing "the object"."the variable", for exemple : player.x = .....
-x : the x position.
-y : the y position.
-gravity : this is the amout of gravity for exemple if gravity = 0.5 the object will start falling automatically, but if the gravity = 0 the player will not fall down.
-direction : the direction of the object.
-speed : the speed of the object if speed is bigger than 0 the object will move depending on it's direction.
-hspeed : the horizontal speed.
-vspeed : the vertical speed.
There are also some variable used for the sprite of the object :
-sprite_index = the name of the sprite of the object, it's used to change the sprite of the object during the game like when the player move or jump ...
Some functions :
There are a lot of functions in GameMaker, the most importaants are :
-keyboard_check() : this will check if the key is pressed for every step.
Exemple :
if keyboard_check(vk_right){
x += 4;
}
This code will check if the player is pressing the right key, if true the object will move by 4 pixel evey step.
-keyboard_check_pressed() : the same as the other but in this case when return true it will perform the action but not every step just one time.
Exemple :
if keyboard_check_pressed(vk_right){
x += 4;
}
This code will check if the up key is pressed if true the object will move right by 4 pixel but one time not every step, this will let the object move evey time the player press the button.
-keyboard_check_released() : this is the opposite of the other, it will check if the player release a key.
-instance_create(x,y,object) : this function will create an object at the indicated position (x,y).
-instance_destroy() : this will destroy the current object, if you want to destroy an object from another object's code use :
with(The Object){
instance_destroy();
}
-room_goto(Room's name) : this will go to the indicated romm's name.
So these are the most importants variables and functions to make a complete game, i hope it was helpful.
Comments
Post a Comment