issue changing between sprites of different frame count

The issue I'm having is that my animation is freezing on image_ index = 0 ,
The initial sprite in use is made up of only one image ( spr_enemy) and in the code I switch it out for
spr_EnemyBP which is made
up of two images. The switch is made by a boolean variable that is set to true when my enemy is at a certain range of my player.
The code works in that the boolean is set to true and the sprite change does happen but the
Issue being the animation switch is stuck on the first frame. I changed spr_enemy out for a 2 image
animation and then the preceding animation did work. What bit of code am I missing ? I tried setting image_index to 0
because I read somewhere that would help but it did not. Is there a convention I have yet to learn regarding
sprites of different lengths? The code is below with the sprites in bold.




if( Hit == false && Hit2 == false && Down==false && CurrentHp > 0)
{
sprite_index = spr_enemy; // if I change to a sprite_index that has the same sub images as spr_EnemyBP it works

if (distance_to_object(obj_Player) < .25 && abs(y - obj_Player.y) < .75)
{
isAttacking = true ;
}
}
if ( isAttacking = true) { sprite_index = spr_EnemyBP } // tried setting image_index to 0
 
Last edited:

obscene

Member
Sorry there's just not enough information here to figure this out. It's right possible both of those statements are true and the spread is constantly being set back and forth. You may have other code somewhere else affecting the image index or speed as well.

Also make sure you use code tags when posting code on the forum, it makes it easier to read.
 

TheouAegis

Member
Check if the sprite is not your target sprite before changing sprites (or use a state machine that operates on the presumption the current sprite is incorrect),then you can change the sprite and set image_index to 0 that ONE TIME instead of every step.
 
Check if the sprite is not your target sprite before changing sprites (or use a state machine that operates on the presumption the current sprite is incorrect),then you can change the sprite and set image_index to 0 that ONE TIME instead of every step.
Im about to do some clean up which will involve recoding a ton of things into switch statements. Ive "solved" this issue but not sure how ,lol. Got to clean up my code .
 
Top