Corona SDK多点触控运行和跳转

时间:2017-02-16 09:45:18

标签: android mobile lua corona

我认为这应该很容易,但我找不到任何解决方案。它始终只是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()方法。但到目前为止,在跑步时,我不能跳,直到我释放右键。

1 个答案:

答案 0 :(得分:0)

我的错误是,我想使用TAP事件进行跳转。我猜因为它被称为multiTOUCH它只适用于多个TOUCH事件:)我将TAP事件更改为TOUCH事件并添加:

rails c --sandbox

现在效果很好。