J
JonahJSanders
Guest
Hello,
I am pretty new to Game Maker, and completely new to coding!
I've picked up on a few tricks from watching some videos on how to code 8 directional movement.
I have been able to get the 8 directional movement to work, and I have even been able to get a corresponding directional sprite to work for each direction, the only problem is that when I stop moving (no longer pressing any keys) the player stops, however the sprite continues moving.
I know that I need to find some way to set the sprite_index of the player back to an idle position, but I am not sure of how to do this. If at all possible, I wanted to be able to have the player be facing idle in the direction he was last walking (For example, if he was walking left, when I stop pressing the left key, I just want the player to change to an idle left sprite, the same with right, up, down, etc.)
I also need to work collision into the code as well. I know this can be accomplished with the place_free command but I cannot get it to fit into the code, it just gives me an error and I am not sure how to fix it.
So, to summarize
1)I need to make the player stop when he collides with a solid object
2)I need the player to assume an idle sprite when no keys are being pressed, preferably corresponding to the direction he was walking
I can post the code I am using right now and if anybody would be able to help me out that would be greatly appreciated!
if (keyboard_check(vk_up) && keyboard_check(vk_right))
{x+=2; y-=2; sprite_index=Nuparu_Walk_Up;}
else if (keyboard_check(vk_up) && keyboard_check(vk_left))
{x-=2; y-=2; sprite_index=Nuparu_Walk_Up;}
else if (keyboard_check(vk_down) && keyboard_check(vk_right))
{x+=2; y+=2; sprite_index=Nuparu_Walk_Down;}
else if (keyboard_check(vk_down) && keyboard_check(vk_left))
{x-=2; y+=2; sprite_index=Nuparu_Walk_Down;}
else if keyboard_check(vk_up)
{x+=0; y-=4; sprite_index=Nuparu_Walk_Up;}
else if keyboard_check(vk_left)
{x-=4; y-=0; sprite_index=Nuparu_Walk_Left;}
else if keyboard_check(vk_down)
{x+=0; y+=4; sprite_index=Nuparu_Walk_Down;}
else if keyboard_check(vk_right)
{x+=4; y-=0; sprite_index=Nuparu_Walk_Right;}
I am pretty new to Game Maker, and completely new to coding!
I've picked up on a few tricks from watching some videos on how to code 8 directional movement.
I have been able to get the 8 directional movement to work, and I have even been able to get a corresponding directional sprite to work for each direction, the only problem is that when I stop moving (no longer pressing any keys) the player stops, however the sprite continues moving.
I know that I need to find some way to set the sprite_index of the player back to an idle position, but I am not sure of how to do this. If at all possible, I wanted to be able to have the player be facing idle in the direction he was last walking (For example, if he was walking left, when I stop pressing the left key, I just want the player to change to an idle left sprite, the same with right, up, down, etc.)
I also need to work collision into the code as well. I know this can be accomplished with the place_free command but I cannot get it to fit into the code, it just gives me an error and I am not sure how to fix it.
So, to summarize
1)I need to make the player stop when he collides with a solid object
2)I need the player to assume an idle sprite when no keys are being pressed, preferably corresponding to the direction he was walking
I can post the code I am using right now and if anybody would be able to help me out that would be greatly appreciated!
if (keyboard_check(vk_up) && keyboard_check(vk_right))
{x+=2; y-=2; sprite_index=Nuparu_Walk_Up;}
else if (keyboard_check(vk_up) && keyboard_check(vk_left))
{x-=2; y-=2; sprite_index=Nuparu_Walk_Up;}
else if (keyboard_check(vk_down) && keyboard_check(vk_right))
{x+=2; y+=2; sprite_index=Nuparu_Walk_Down;}
else if (keyboard_check(vk_down) && keyboard_check(vk_left))
{x-=2; y+=2; sprite_index=Nuparu_Walk_Down;}
else if keyboard_check(vk_up)
{x+=0; y-=4; sprite_index=Nuparu_Walk_Up;}
else if keyboard_check(vk_left)
{x-=4; y-=0; sprite_index=Nuparu_Walk_Left;}
else if keyboard_check(vk_down)
{x+=0; y+=4; sprite_index=Nuparu_Walk_Down;}
else if keyboard_check(vk_right)
{x+=4; y-=0; sprite_index=Nuparu_Walk_Right;}