2017-02-16 6 views
0

これは非常に簡単に行うべきだと思いますが、解決策を見つけることができません。常にちょうどsystem.enable("multitouch")であり、次にsetFocus()メソッドで何かが起こります。 私は右ボタンを持っています。これはタッチイベントに応答し、開催時にプレイヤーを右に走らせます。それから私はジャンプボタンを持っています。それはタップイベントに反応し、プレーヤーをジャンプさせます。 仕事をしたり、ジャンプしたりしますが、走ってジャンプしても何も起こりません。コロナSDKマルチタッチ実行とジャンプ

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) 

私はknowhしていない場合は、どのようにか、なぜ私はは、setFocus()メソッドを使用する必要があります。 はここにいくつかのコードです。しかし、これまでのところ、私が右ボタンを放すまでジャンプすることはできません。

答えて

0

ジャンプのためにTAPイベントを使用したかったのは間違いでした。私はそれがマルチタッチと呼ばれているので、それが唯一の複数のタッチイベントと連携推測:)私は、イベントをタッチするTAPイベントを変更して、コメントを追加:

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 

は、今ではうまく動作します。

関連する問題