Making my sprite to flicker (SOLVED)

Right now, I am making a fighting game. when my main character gets attacked by enemy, I want to make him to flicker 3-4 times. I tried doing this, but I am not familiar with easing and I’m not sure how to make my character to flicker several times.

if message_id == hash("trigger_response") and message.group == hash("enemy_hitbox")then
	--print('touch')
	if self.attacked == nil then
		self.attacked = true
		local pos = go.get_position()
		go.animate("#sprite", "tint", go.PLAYBACK_ONCE_PINGPONG, vmath.vector4(1, 1, 1, 0), go.EASING_INOUTBOUNCE, 0.3,0,anim_done)
	end
end

Since you are dealing with on/off states, you could use a timer.delay() to alter the visual appearance of the sprite a couple of times before disabling the timer.

I tried this:

local i
	i = 0
	timer.delay(1, true, function(self,handle,time_elapsed)
		if i<3 or i ==3 then 
			go.animate("#sprite", "tint", go.PLAYBACK_ONCE_PINGPONG, vmath.vector4(1, 1, 1, 0), go.EASING_LINEAR, 0.3,0,anim_done)
			i = i+1
		elseif i > 3 then
			timer.cancel(handle)
		end
	end)

When I did this, My sprite gets lighter and lighter and does not come back to its original alpha. What did I do wrong?

That code worked for me (as far as I can tell).
Where did you put it/how do you invoke it?

Never mind. I was trying to test it with

if action_id == hash("reset") then

and I realized that I did not put and action.pressed. Now it’s working. Thank you for your help!

2 Likes