Changing sprite when colliding with an object

C

Costco2

Guest
Hello there, I've been trying to change my sprite index to a hurt sprite when my rock object collides with my hero sprite, in my rock object I have this written:

with (other)
{

hp = hp - 25;
sprite_index = sHeroHurt;

}
instance_destroy()

It seems to only flash it for a brief second, I was trying to add a collision code on the hero object but that didn't seem to work, I've been lurking around at other post and someone noted an alarm statement, but I couldn't figure out the code to get it to work, any help or thoughts would be greatly appreciated!
 
You can make a variable hurtFrames in the hero object saying for how many steps he should still be hurt. Set it to 0 in the Create event, and to e.g. 20 in the collision event, and in the step event of the hero, if hurtFrames > 0, subtract 1 from it and set sprite_index to sHeroHurt.

Edit: Or perhaps rather in the End Step event, to make sure other game logic doesn't override it.
 
Instead of other you could put your player object name, because lets say you had another instance that is like a sign post or something it will not change that sprite index too. As for your question that code is only being executed when the rock is colliding with the player so my question is, are you changing the sprite index back when the rock is destroyed, If I’m wrong than check what changes your sprite index back to normal for your hero, otherwise the problem is that the rock destroys itself when it hits the player causing the sprite to flicker to the hurt sprite and back, hope this helps!
 
Top