How do I change sprite animations after picking up a weapon?

Hello everyone,

I have imported a sprite sheet featuring my character running with a weapon. I was hoping to use this animation after the player picks up the weapon object. However, I'm unsure about how to insert the animation into the code. I know it has to take the form of an if statement, but I'm unsure as to how to implement it, without causing any trouble down the line as I insert power ups and other weapons. I wanted to use finite state machines to switch between an unarmed state and an armed state, but I don't know if that's too complicated for what I want to accomplish and I'm unsure as to how to implement that as well. I inserted most of the code in the player step event into PlayerNormal script minus the animations. Here is the code:

Player_Normal();


#region //Animation

if(!place_meeting(x,y+1,Owall))
{
sprite_index = SplayerA;
image_speed = 1;
if sign(vsp) < 0 and image_index > image_index= 68 //if going up and animation passes halfway
{
image_index = image_index= 68;
}
}
else
{
canjump= 10;
if(sprite_index == SplayerA)
{
audio_sound_pitch(snLanding,choose(0.8,1.0,1.1));
audio_play_sound(snLanding,4,false);
repeat(5)
with(instance_create_layer(x,bbox_bottom,"Bullets",Odust))
{
vsp = 0;
}

}
image_speed = 1;
if (hsp==0)
{
sprite_index = Splayer

}
else
{
sprite_index = SplayerR;
}
}

Also, currently the gun is a separate object and sprite.

if(hsp != 0) image_xscale = sign(hsp)

#endregion
 
Last edited:

curato

Member
you just need a variable for picking up the weapon and then just use and if statement to switch the sprite_index to the one with the weapon.
 

curato

Member
you either have to draw them together as the same sprite or you could overide your draw even and draw the base sprite for the player then draw the gun after that and assuming everything is animated properly they will look like one sprite.
 
Top