GML Visual change sprite index then change back to original

W

WingBat

Guest
Good evening all.

So I may be going about this the wrong way. What I am trying to accomplish is when the player (obj_player) gets hit by the enemy spawn (obj_enemy) the sprite changes to an "ouch" face. I can do this with the sprite_index code for GML. I figured that much out but once it changed to the "ouch" face I cant get it to go back to the original sprite. Does anyone have any recommendations on how to accomplish this?
 
Last edited by a moderator:
Use an alarm. When the player gets hit, change the sprite_index. Set the alarm to a low value like 2 or 3 ( you can experiment with the value to get the right feeling for the effect you want).

In the alarm event, set the sprite_index back to normal
 
K

Kuro

Guest
In the create event of obj_player, you can store your default sprite in a variable using the following GML:
Code:
default_sprite = sprite_index;
So then whenever you want to change the sprite back just set the sprite_index = default_sprite.
 
Are you sure you need to change the entire sprite index? Perhaps simply incrementing the image index on the current sprite index would suffice.
Regardless, you should set an alarm after the player gets hit, and when that alarm is done, re-set the sprite index. (You could do that with Kuro's suggestion above)
 
W

WingBat

Guest
Use an alarm. When the player gets hit, change the sprite_index. Set the alarm to a low value like 2 or 3 ( you can experiment with the value to get the right feeling for the effect you want).

In the alarm event, set the sprite_index back to normal
This worked thank you so much!
 
Top