- Title: Perfect Platform Walking tutorial with example
- Description: Perfect Platform Walking Code easy to understand with explanation.
- GM Version: GM8.1
- Registered: Yes
- File Type: .zip and gmk.
- File Size: 14.5Kb
- File Link: .Click "Download Form This Server" above
- Required Extension: none
- Required DLL: none
- Tags: tutorial, make, platform,help, guide,beginner,
SummaryThis tutorial shows the right code for walking with animation easy to understand with explanation.
Solves the following problems : Moonwalking, the problem when you walk to a direction and then you turn reverse direction the object stops,
Im also a beginner i tried many codes myself until i created this code.
This is the code i made.
you need to put this under step event of your player object.
// this is for the key press event
if keyboard_check_pressed(vk_left) // if you press the left key
{
hspeed = -2 // you will move to the left Note: You can modify this depending on the speed you want when going left
image_speed = 0.1 // this is the animation speed of your sprite
}
if keyboard_check_pressed(vk_right) // if you press the right key
{
hspeed = 2 // you will move to the right Note: You can modify this depending on the speed you want when going right
image_speed =0.1 // this is the animation speed of your sprite
}
//This is for the key release event
if keyboard_check_released(vk_right) // if you release the right key
{
if hspeed >= 0 // this is to check if youre moving (if horizontal speed is larger than 0 )
{
hspeed = 0 // this will make your object stop, since were using hspeed(horizontal speed) i set this to hspeed
image_index = 0 // this will set the frame number or index of your animated sprite to 0
image_speed = 0 // this sets the animation speed of your sprite to 0
}
}
if keyboard_check_released(vk_left) // if you release the left key
{
if hspeed <= 0 // this is to check if youre moving (if horizontal speed is larger than 0 )
{
hspeed = 0 // this will make your object stop, since were using hspeed(horizontal speed) i set this to hspeed
image_index = 0 // this will set the frame number or index of your animated sprite to 0
image_speed = 0 // this sets the animation speed of your sprite to 0
}
}
//this sets the correct sprite.
if hspeed = -2 // if you are moving (left) note : if you modify the hspeed above you also need to change this
{
sprite_index = spr_playerleft //sets the sprite to left note: you can change this depending on your sprite's name mine is spr_playerleft
}
if hspeed = 2 // if you are moving (right) note : if you modify the hspeed above you also need to change this
{
sprite_index = spr_playerright
//sets the sprite to right note: you can change this depending on your sprite's name mine is spr_playerright
}
Hope this helps..
thank you for your time
if you ever had questions or parts that you did not understand im willing to read comments.
//chestertagat