Play Animation While Object is Moving

C

c2h6.sk8

Guest
Okay so I'll keep this as basic as possible, but I'm trying to animate my player character so that the animation only plays while the character is moving. I have seperate sprites for left, right, up, and down, each with their own animations. I've set each keyboard button to transform the front facing sprite to the proper direction and then move at a speed of 1 as long as the key is pressed. But when I try to add the image_speed function to my code, it either doesn't play the animation at all, or only plays while the instance is not moving. I've tried different scripts, and this is my current for the left button press:

x -= 1
image_speed = 0.2

if speed = 0
{
image_speed = 0;
}

I know this is probably way off but I'm kind of new to the program itself. If someone could help me out, that'd be great. Each directional sprite has a still frame and two movement frames if anyone needs to know.
 
C

c2h6.sk8

Guest
I found a way to make it work by seperating the animations into seperate sprites so now the still sprite is on its own and switches to the animated when the correct key is held, but if it was possible to have it like I originally did that would help.
 
G

Gillen82

Guest
if you want to keep it similar to what you have you could use the code below

Code:
if( speed = 0 ) {

    image_speed = 0;
    image_index = 0; //Ensures that the animation is on the first frame of the animation

} else {

    image_speed = 1; //Sets to 100% speed of the room speed

}
You could also set it per key:

Code:
if ( keyboard_check( vk_right ) ) {
    speed = 2;
    image_speed = 1;
}
 
C

c2h6.sk8

Guest
if you want to keep it similar to what you have you could use the code below

Code:
if( speed = 0 ) {

    image_speed = 0;
    image_index = 0; //Ensures that the animation is on the first frame of the animation

} else {

    image_speed = 1; //Sets to 100% speed of the room speed

}
You could also set it per key:

Code:
if ( keyboard_check( vk_right ) ) {
    speed = 2;
    image_speed = 1;
}

Thank you this helps a lot :)
 

Genetix

Member
I have my player or NPC's checkt their direction in the step event and call a script check_face() each step as well. This script works specifically for a character that faces up,left,down,right with 36 sprites - but could be tweaked as needed. In the event where a button or control is used to move a character their image_speed = .15 else image_speed = 0 Not sure how much this will help you but worth sharing.

Here is the code for the check_face() script:

Code:
if my_face = 0 //Top
{if image_index > 8 {image_index = 0}}

if my_face = 1 //Left
{if image_index < 9 {image_index = 9} if image_index > 17 {image_index = 9}}

if my_face = 2 //Down
{if image_index < 18 {image_index = 18} if image_index > 26 {image_index = 18}}

if my_face = 3 //Right
{if image_index < 27 {image_index = 27} if image_index > 35 or image_index = 0 {image_index = 27}}



//Check direction
if direction >= 45 and direction < 135 {my_face = 0} //Top
if direction >= 135 and direction < 225 {my_face = 1} //Left
if direction >= 225 and direction < 315 {my_face = 2} //Down
if direction >= 315 or direction < 45 {my_face = 3}//Right
 
D

Diveyoc

Guest
What about something like this is your player step event.
image_speed = speed/25;
That way anytime your player moves, the image speed kicks in. At a speed of 5, the image speed would be 0.2
 
Top