“idle_rightUp” animation can not run. Is there a way to run an idle animation for the “right-up” direction?
function on_input(self, action_id, action)
if action_id == hash("right") and action.released then
movement = 0 --right
sprite.play_flipbook("#sprite", "idle_right")
elseif action_id == hash("right") and hash("up") and action.released then
movement = 1 --rightUp
sprite.play_flipbook("#sprite", "idle_rightUp")
elseif action_id == hash("up") and action.released then
movement = 2 --up
sprite.play_flipbook("#sprite", "idle_up")
--...
end
end
In another method I tried. Walking motion animation works successfully for 8 directions. Idle animation works only “right, up, left, down” directions but idle animation not working for intermediate (up-right, …) directions. it is necessary to release the up and right keys at the same time. but this is not possible. This is not possible for other intermediate directions either too. Thanks for your help?
function update(self, dt)
pos=go.get_position()
go.set_position(pos + self.direction * self.speed * dt)
end
function on_input(self, action_id, action)
if action_id == hash("right") then
b_r = 1
play_animation(self)
elseif action_id == hash("up") then
b_u = 1
play_animation(self)
elseif action_id == hash("left") then
b_l = 1
play_animation(self)
elseif action_id == hash("down") then
b_d = 1
play_animation(self)
end
elseif action.released then
if action_id == hash("right") then
b_r = 0
play_animation(self)
elseif action_id == hash("up") then
b_u = 0
play_animation(self)
elseif action_id == hash("left") then
b_l = 0
play_animation(self)
elseif action_id == hash("down") then
b_d = 0
play_animation(self)
end
end
end
local function play_animation(self)
if b_r==1 and b_u==0 and b_l==0 and b_d==0 then
--sprite.play_flipbook("#player", "r_w")
self.direction.x=1
self.direction.y=0
plYon=0
elseif b_r==1 and b_u==1 and b_l==0 and b_d==0 then
--sprite.play_flipbook("#player", "ur_w")
self.direction.x=1
self.direction.y=1
plYon=1
elseif b_r==0 and b_u==1 and b_l==0 and b_d==0 then
--sprite.play_flipbook("#player", "u_w")
self.direction.x=0
self.direction.y=1
plYon=2
elseif b_r==0 and b_u==1 and b_l==1 and b_d==0 then
--sprite.play_flipbook("#player", "ul_w")
self.direction.x=-1
self.direction.y=1
plYon=3
elseif b_r==0 and b_u==0 and b_l==1 and b_d==0 then
--sprite.play_flipbook("#player", "l_w")
self.direction.x=-1
self.direction.y=0
plYon=4
elseif b_r==0 and b_u==0 and b_l==1 and b_d==1 then
--sprite.play_flipbook("#player", "dl_w")
self.direction.x=-1
self.direction.y=-1
plYon=5
elseif b_r==0 and b_u==0 and b_l==0 and b_d==1 then
--sprite.play_flipbook("#player", "d_w")
self.direction.x=0
self.direction.y=-1
plYon=6
elseif b_r==1 and b_u==0 and b_l==0 and b_d==1 then
--sprite.play_flipbook("#player", "dr_w")
self.direction.x=1
self.direction.y=-1
plYon=7
end
if b_r==1 or b_u==1 or b_l==1 or b_d==1 then
if plYon==0 then sprite.play_flipbook("#player", "r_w")
elseif plYon==1 then sprite.play_flipbook("#player", "ur_w")
elseif plYon==2 then sprite.play_flipbook("#player", "u_w")
elseif plYon==3 then sprite.play_flipbook("#player", "ul_w")
elseif plYon==4 then sprite.play_flipbook("#player", "l_w")
elseif plYon==5 then sprite.play_flipbook("#player", "dl_w")
elseif plYon==6 then sprite.play_flipbook("#player", "d_w")
elseif plYon==7 then sprite.play_flipbook("#player", "dr_w")
end
end
--here is the problem. When I release the right and up button,
--the plYon value should be 1. But I cannot release 2 buttons
--at the same time. The last released button is either right button or up
--button. plYon=0 or plYon=2
if b_r==0 and b_u==0 and b_l==0 and b_d==0 then
self.direction.x=0
self.direction.y=0
if plYon==0 then sprite.play_flipbook("#player", "r_i")
elseif plYon==0 then sprite.play_flipbook("#player", "r_i")
elseif plYon==1 then sprite.play_flipbook("#player", "ur_i")
elseif plYon==2 then sprite.play_flipbook("#player", "u_i")
elseif plYon==3 then sprite.play_flipbook("#player", "ul_i")
elseif plYon==4 then sprite.play_flipbook("#player", "l_i")
elseif plYon==5 then sprite.play_flipbook("#player", "dl_i")
elseif plYon==6 then sprite.play_flipbook("#player", "d_i")
elseif plYon==7 then sprite.play_flipbook("#player", "dr_i")
end
end
...
end