i just want to create a death animation to my hero…i want to change the image/animation of a sprite whenever it collides into an object(enemy) so it will animate as destroyed…i actually use this method in my first attempt:
-i created a GO named “hero” which contain 2 sprited (named “hero_normal” and “hero_destroyed”)
-i created a script for my hero and put it in the hero GO i created.
in function init(), i actually disabled the “hero_destroyed” sprite so it will not show whenever i start the game in the editor. i put this code:
msg.post("#hero_destroyed", “disable”)
msg.post("#hero_normal", “enable”)
and in function on_message(), i enabled the hero_destroyed and disabled the hero_normal whenever it collides into an enemy and restart the game…but what happened is whenever i collides into an enemy, it not actually plays the destroyed animation whenever it hit an enemy…can you help me find a solution to this?..any help is really appreciated…thank you very much! :’)
I do this, my animation is in an animation group in the atlas.
This does have an issue though, it plays the first frame of animation at 0, but plays all 4 when it hits -1.
go.property(“timer”, 0) – Use to time events
function on_message(self, message_id, message, sender)
if message_id == hash(“0_lives”) then
msg.post("#sprite", “play_animation”, {id = hash(“death”)})
– pause 2 sec
go.animate("#", “timer”, go.PLAYBACK_ONCE_FORWARD, 2, go.EASING_LINEAR, 0.2, 0, function ()
– msg.post(“loader:/load#loader”, “game_over”)
msg.post(“loader:/load#level_complete”, “level_completed”)
end)
elseif message_id == hash(“1_lives”) then
msg.post("#sprite", “play_animation”, {id = hash(“hit_damaged_1”)})
elseif message_id == hash(“2_lives”) then
msg.post("#sprite", “play_animation”, {id = hash(“hit_damaged_2”)})
elseif message_id == hash(“3_lives”) then
msg.post("#sprite", “play_animation”, {id = hash(“hit_damaged_3”)})
end
end
@CDaniel – Thank you very much for your reply…i got now an idea…and i apply it to my game…it works fine for me… :’)
1 Like