Animation not working :/

J

Jack

Guest
This is happening in a (Press X key) event.

sprite_index = spr_player_attack;
image_index = 0;
image_speed = 1;

The animation doesnt work even though im setting the image speed. Someone please help!!!
 

jo-thijs

Member
We'll need more information in order to help you.
Could you provide the object information of the regarding object?

It might be that some other code undoes the animation.
 
B

Brrrzzz

Guest
This is happening in a (Press X key) event.

sprite_index = spr_player_attack;
image_index = 0;
image_speed = 1;

The animation doesnt work even though im setting the image speed. Someone please help!!!
Did you write that code in the step event? That would set the image_index in every step to 0, so it could not really animate anything...I think.
 
N

nujumkey

Guest
What @Brrrzzz said.
Try setting an alarm on the animation start so that your code can only run once every couple of seconds, that way you know if your code is overwriting itself
 
J

Jack

Guest
k heres the objects stuff

Step Event:
//sprites
image_index=0;
image_speed=0;

//LR animations (working)
if (keyboard_check(ord('D'))) {
image_index=1;
}

if (keyboard_check(ord('A'))) {
image_index=2;
}


//player movement
hspeed = flyspd * (keyboard_check(ord('D')) - keyboard_check(ord('A')));
vspeed = flyspd * (keyboard_check(ord('S')) - keyboard_check(ord('W')));



//collisions
if hspeed!=0
if !place_free(x+hspeed,y)
{
if hspeed>0 move_contact_solid(0,hspeed)
if hspeed<0 move_contact_solid(180,-hspeed)
hspeed=0
}

if vspeed!=0
if !place_free(x+hspeed,y+vspeed)
{
if vspeed>0 move_contact_solid(270,vspeed)
if vspeed<0 move_contact_solid(90,-vspeed)
vspeed=0
}

Press X Event (not working, only playing one frame of the animation)

sprite_index = spr_player_attack
image_index = 0;
image_speed = 1;

Release X Event

sprite_index = spr_player;
image_index = 0;
 

jo-thijs

Member
So it is indeed a code in the step event that is constantly resetting image_index.

You can solve this issue by ommitting this piece of code:
//sprites
image_index=0;
image_speed=0;

//LR animations (working)
if (keyboard_check(ord('D'))) {
image_index=1;
}

if (keyboard_check(ord('A'))) {
image_index=2;
}

by:
if sprite_index != spr_player_attack {
...
}
 
J

Jack

Guest
Im not understanding what (if sprite_index is not = spr_player_attack) will do? I think this would go before the other animation code am I correct?
 

jo-thijs

Member
Oops, I meant surround, not omitting.
Surrounding that piece of code with that if statement will prevent the animation code
for the not attacking animation from executing if the player has an attacking animation.
 
J

Jack

Guest
Ok, Ill try to write this, but please tell me how you would right it. (sorry for dragging this on)
EDIT: yea im not sure how to write this please show me how you are thinking of writing this.
 

jo-thijs

Member
Sorry for confusing you, try this as step event:

STEP EVENT:
Code:
if sprite_index != spr_player_attack {
    //sprites
    image_index=0;
    image_speed=0;
 
    //LR animations (working)
    if (keyboard_check(ord('D'))) {
        image_index=1;
    }
 
    if (keyboard_check(ord('A'))) {
        image_index=2;
    }
}

//player movement
hspeed = flyspd * (keyboard_check(ord('D')) - keyboard_check(ord('A')));
vspeed = flyspd * (keyboard_check(ord('S')) - keyboard_check(ord('W')));



//collisions
if hspeed!=0
if !place_free(x+hspeed,y)
{
if hspeed>0 move_contact_solid(0,hspeed)
if hspeed<0 move_contact_solid(180,-hspeed)
hspeed=0
}

if vspeed!=0
if !place_free(x+hspeed,y+vspeed)
{
if vspeed>0 move_contact_solid(270,vspeed)
if vspeed<0 move_contact_solid(90,-vspeed)
vspeed=0
}
 
J

Jack

Guest
Dude, I cannot thank you enough! I struggle on little things like this for hours on end. Thanks so much for the help!
 

Yal

šŸ§ *penguin noises*
GMC Elder
Don't forget to mark the topic solved using the 'solved' prefix~


(Insert rant about reading all of the above to no avail here)
 
Top