Corona SDK 多点触控 运行 和跳转
Corona SDK multitouch run and jump
我认为这应该很容易做到,但我找不到任何解决方案。它总是 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() 方法。但是到目前为止运行宁,我不能跳,直到我释放右键。
我错了,我想用TAP事件跳转。我想因为它被称为 multiTOUCH,它只适用于多个 TOUCH 事件 :) 我将 TAP 事件更改为 TOUCH 事件并添加:
if event.phase == "began" then
display.getCurrentStage():setFocus( event.target, event.id )
--other code
end
if event.phase == "ended" or event.phase == "cancelled" then
display.getCurrentStage():setFocus( event.target, nil )
end
现在效果很好。
我认为这应该很容易做到,但我找不到任何解决方案。它总是 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() 方法。但是到目前为止运行宁,我不能跳,直到我释放右键。
我错了,我想用TAP事件跳转。我想因为它被称为 multiTOUCH,它只适用于多个 TOUCH 事件 :) 我将 TAP 事件更改为 TOUCH 事件并添加:
if event.phase == "began" then
display.getCurrentStage():setFocus( event.target, event.id )
--other code
end
if event.phase == "ended" or event.phase == "cancelled" then
display.getCurrentStage():setFocus( event.target, nil )
end
现在效果很好。