How to delete game object after animation?

hi i am looking for ideas on how to delete my GO after it finishes its animation

function on_message(self, message_id, message)
	if message_id == hash("sword") then 
		msg.post("#sprite", "play_animation", {id = hash("death")})		
	elseif message_id == hash("animation_done") then
		go.delete()
	end
end

Thanks in advance

The code you shared should delete the game object after the animation has finished.

BUT

This is the old and almost deprecated way of starting an animation. I would recommend sprite.play_flipbook() instead, and use the callback function to delete the game object.

1 Like