olzaffiliate.blogg.se

Game maker studio 2 platformer animation
Game maker studio 2 platformer animation






If (keyboard_check_pressed(vk_up) and not place_free(x, y + 1)) vspeed = -13 Open your Step event once more and append this code: You’ll see that the player can move around. If you want to, you can try playing your game.

game maker studio 2 platformer animation

Now copy the code above and add it into your Step event. The x is the horizontal position of the object, and y is its vertical position.

game maker studio 2 platformer animation

So, we’re checking if there is no solid object (here, obj_block) before us before we move. The place_free() function is used to check if the specified place is free from any solid objects. So now that there are two conditions, the hspeed will be changed only if both of them turn out true. What has changed? Yes, there is one more condition, after the and. If (keyboard_check(vk_right) and place_free(x + 3, y)) hspeed = 3 If (keyboard_check(vk_left) and place_free(x – 3, y)) hspeed = -3 So, we’re putting a condition (using “if ()”) and then changing hspeed if the condition turns out true. But if the right key too is not pressed, it just changes hspeed to 0, causing the player to stop. If left key is not pressed, as an alternative it checks for the right key and turns hspeed to 3 so the player moves to the right. It checks if we’ve pressed the left key, then changes hspeed to -3, so the object moves to the left. If on keyboard right key is pressed, set horizontal speed to 3. Hey, if on keyboard left key is pressed, set horizontal speed to -3. Keyboard_check() is used to check if a key is being pressed on the keyboard, and hspeed is the horizontal movement speed of the object. If you’re not familiar with coding, this might seem a bit confusing. If (keyboard_check(vk_right)) hspeed = 3 If (keyboard_check(vk_left)) hspeed = -3 Before adding any code in there, take a look at this piece of code.

game maker studio 2 platformer animation

This will stop the player from falling (due to gravity) when it collides with the block object, by turning its vertical speed (vspeed) to 0. So now our player object has gravity and will stick to the ground (as long as it is there).Īdd a collision with obj_block event and add this code: Add an Execute Code action from the control drop-down menu. Open your obj_player and add the Create event. Place the objects in a room and make a level. When you create the obj_block, tick the Solid option. One will be spr_player (for the player) and the other spr_block (which will act as the walls/floor). This is for beginners who want to learn GML. Hey there folks! In this tutorial we’re going to create a simple platformer in GameMaker: Studio, using GML (Game Maker Language).








Game maker studio 2 platformer animation