Post 91
Exporting & Importing
- Not Drugs, Sorry.
Instead of re-doing the running animation right away, I decided to create a testing environment for my sprites. First I had to export a selection of my animations. I ran into a few problems with exporting, but only because I accidentally checked the wrong option, so that problem was quickly fixed.Then I selected all 125 images and put them into Game Maker.
Then I had to repeat the process and flip the image as a whole, instead of flipping each image as a separate picture, which I can say confidently would take me 125 times longer then the way I did it. Either way I switched it so it would be both the left and right animation for being idle.
I then exported the walking animation and imported it into Game Maker. Doing the exact same process to create to separate animations, one for each direction.
Coding the Basics
After I got all my sprites setup I dove into code. I learned how to create a successfully animated walking character in Game Maker Studios, and this is how I did it.
First by creating some variables like
Idle = 1; - The idea behind this Idle variable is to tell the game which Spr_Player_Idle sprite it needs. Whether its the left one, or the right one. So in order to make the Variable work I had to assign a meaning behind its pointless number value - with the following code.
What Activates the code to act will be labelled in Orange.
What happens when the code is active will be Red.
Notes for helping the understanding of code will be Light Grey.
Obj_Player/Step Event/
if (idle = 1)
{
sprite_index = spr_player_idle_left;
(If Idle is set as 1, change the sprite to the left version)
}
if (idle = 2)
{
sprite_index = spr_player_idle_right;
(If Idle is set as 1, change the sprite to the right version)
}
This makes the sprite change according to the number that is currently assigned to the variable Idle.
But currently the variable Idle has no way to change. So I needed to add in a little bit more code.
Obj_Player/Step Event/
if (keyboard_check(ord("A")))
{
sprite_index = spr_player_walking_left;
idle = 1
x -= playerspeed;
(When the A key is pressed - Set Sprite to the Walking Left Sprite, Set the Idle Stance to Left, And Make the Player moved left on his X Axis)
}
if (keyboard_check(ord("D")))
{
sprite_index = spr_player_walking_right;
idle = 2
x += playerspeed;
(When the D key is pressed - Set Sprite to the Walking right Sprite, Set the Idle Stance to right, And Make the Player moved right on his X Axis)
}
As you can see, I added some basic controls. Along with a system that sets the Idle value to the correct number upon movement. This allows the player to be idle in the last direction they were moving. Here is a visual demonstration of what I have learned today! Tomorrow I will change the sprinting animation and possibly add more to my visual demo!
Idle = 1; - The idea behind this Idle variable is to tell the game which Spr_Player_Idle sprite it needs. Whether its the left one, or the right one. So in order to make the Variable work I had to assign a meaning behind its pointless number value - with the following code.
What Activates the code to act will be labelled in Orange.
What happens when the code is active will be Red.
Notes for helping the understanding of code will be Light Grey.
Obj_Player/Step Event/
if (idle = 1)
{
sprite_index = spr_player_idle_left;
(If Idle is set as 1, change the sprite to the left version)
}
if (idle = 2)
{
sprite_index = spr_player_idle_right;
(If Idle is set as 1, change the sprite to the right version)
}
This makes the sprite change according to the number that is currently assigned to the variable Idle.
But currently the variable Idle has no way to change. So I needed to add in a little bit more code.
Obj_Player/Step Event/
if (keyboard_check(ord("A")))
{
sprite_index = spr_player_walking_left;
idle = 1
x -= playerspeed;
(When the A key is pressed - Set Sprite to the Walking Left Sprite, Set the Idle Stance to Left, And Make the Player moved left on his X Axis)
}
if (keyboard_check(ord("D")))
{
sprite_index = spr_player_walking_right;
idle = 2
x += playerspeed;
(When the D key is pressed - Set Sprite to the Walking right Sprite, Set the Idle Stance to right, And Make the Player moved right on his X Axis)
}
As you can see, I added some basic controls. Along with a system that sets the Idle value to the correct number upon movement. This allows the player to be idle in the last direction they were moving. Here is a visual demonstration of what I have learned today! Tomorrow I will change the sprinting animation and possibly add more to my visual demo!
No comments:
Post a Comment