Hello reader,
While making a top down game I came to a problem with attack animations in different directions
Was trying to making a code like this ( this code is just a idea of what I am hoping for )
After looking though many provided examples I found that the LEFT and RIGHT animation can be switched using the commend ( sprite.set_hflip ),
however I have not been able to find a way to add the UP and DOWN attack animations. How would a code for this be written ?
Thanks for reading
It depends a bit on your input. The easiest way is probably to set the direction with the keys you use for controlling the characters movement then use the direction when playing your attack animation.
on_input(self, action_id, action)
if action.pressed and action_id == hash("left") then
self.slash_direction = hash("slash_left")
elseif action.pressed and action_id == hash("right") then
self.slash_direction = hash("slash_right")
elseif action.pressed and action_id == hash("up") then
self.slash_direction = hash("slash_up")
elseif action.pressed and action_id == hash("down") then
self.slash_direction = hash("slash_down")
end
if action.pressed and action_id == hash("attack") then
msg.post(".", hash("play_animation"), {id= self.slash_direction })
end
end
4 Likes