【问题标题】:Corona SDK multitouch run and jumpCorona SDK 多点触控跑跳
【发布时间】: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


    【解决方案1】:

    这是我的错误,我想使用 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
    

    现在效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 2013-04-01
      • 2012-02-26
      • 1970-01-01
      相关资源
      最近更新 更多