【发布时间】:2017-07-05 08:16:57
【问题描述】:
我认为这应该很容易做到,但我找不到任何解决方案。它总是只是system.enable("multitouch"),然后是 setFocus() 方法。
我有一个右键,它响应触摸事件并使播放器在按住时正确运行。然后我有一个跳转按钮,它响应点击事件,让玩家跳转。
跑步有效,跳跃有效,但是当我跑步并尝试跳跃时,什么也没有发生。
这是一些代码:
local speed = 3
local motionx = 0
-- When right arrow is touched, move character right
function right:touch()
if string.find(player.sequence,"jump") then
player:setSequence("jumpRight")
motionx = speed;
elseif string.find(player.sequence,"duck") then
player:setSequence("duckRight")
else
player:setSequence("goingRight")
motionx = speed;
end
player:play()
end
right:addEventListener("touch",right)
-- When up arrow is tapped, jump character
function jump:tap()
if not isJumping then
if string.find(player.sequence, "goingRight") then
isJumping = true
player:setSequence("jumpRight")
player:setLinearVelocity(0,-120)
end
if string.find(player.sequence, "goingLeft") then
isJumping = true
player:setSequence("jumpLeft")
player:setLinearVelocity(0,-120)
end
if string.find(player.sequence, "duckLeft") then
player:setSequence("goingLeft")
end
if string.find(player.sequence, "duckRight") then
player:setSequence("goingRight")
end
player:play()
end
end
jump:addEventListener("tap",jump)
-- Move character
local function movePlayer (event)
player.x = player.x + motionx;
end
Runtime:addEventListener("enterFrame", movePlayer)
我不知道我应该在哪里、如何或为什么要使用 setFocus() 方法。但是到目前为止,在运行时,我必须松开右键才能跳跃。
【问题讨论】:
标签: android mobile lua coronasdk