Why doesn't my image_index work?

N

no1youngin

Guest
trying to make my sprite turn white for a second once taking damage (by touching the bullet).
the first image_index is the normal enemy, the second is the enemy colored in white. made this code in the step event of the enemy. Why doesn't this work?

if place_meeting(x,y,obj_bullet)
{
image_index = 1;
}

if !place_meeting (x,y,obj_bullet)
{
image_index = 0;
}
 

Dr_Nomz

Member
Maybe it's happening too fast to see? I mean what you've got here is basically telling it to flash for 1 frame out of what, 30? More? It's gonna be hard to tell if anything happened at all with so few frames, I'd recommend 4 or 5 at least. As for the problem at hand, try slowing it down first and see if that helps. (I like to bind a key in my control object that slows it down on key press to like 5 steps per second, and upon releasing the same key it sets it back to normal room speed)
 

samspade

Member
I see a couple issues. First a very minor one. There's no reason to have both if statements. You should only have one.

Code:
if place_meeting(x,y,obj_bullet)
{
    image_index = 1;
}
else
{
    image_index = 0;
}
Second, this code actually is good and would work, so something else must be causing the issue. There are two likely scenarios. The first is that you have other code somewhere else overwriting this. The second, is that you are destroying obj_bullet on contact. So as dr_Nomz pointed out, the image_index will only be 1 for at most one frame, and maybe not even that. For example, if the bullet is destroyed in its own collision or step event, it might be gone before this portion of the code runs later in the same step event.
 
E

Erramir

Guest
i am not a pro but:

while we could find a solution to the code , you actually need a shader to make the character "twinkle"

the code you are attempting to do is more for other stuff like changing a sprite index for when the characters is jumping , walking, running
 

TheouAegis

Member
On bullet collision set the enemy's alarm to 20 or something and set its its image_index to 1. In the alarm event, set image_index to 0.

This is only really suitable for this particular style of hit notification/sprute handling.
 
Top