2

コロナでゲームを作っていて問題に直面しています。画面上に円があり、タッチ座標を継続的に追跡したい。そのために transition.to 関数を使用していますが、この関数が座標を取得するたびに、遷移中に座標が更新されても遷移が完了します。

if event.phase == "began" or event.phase == "moved" then
    follow = true
    touchX = event.x; touchY = event.y
elseif event.phase == "ended" then
    follow = false
end

そして別の機能で、私はこれをやっています

if follow == true then
    transition.to(circle, {time = 500, x = touchX, y = touchY, transition = easing.inOutQuad})
end

コードは単純なタッチでは問題なく動作しますが、円が動いていてもタッチに追従するようにしたいです。

4

2 に答える 2

1

あなたの問題を解決するかもしれないいくつかの例があります。

参照:

1)カルロスがコロナ コミュニティに投稿したフライト パス。

2) renvisでパスを介してオブジェクトを移動する


サンプル:

local circle = display.newCircle(10,10,20)
circle.x = 160
circle.y = 160

local olderTransition
local function moveCircle(e)
  if olderTransition ~= nil then
    transition.cancel( olderTransition )
  end
  olderTransition = transition.to(circle,{time=100,x=e.x,y=e.y})
end
Runtime:addEventListener("touch",moveCircle)

コーディングを続ける........ :)

于 2013-07-17T09:43:28.157 に答える