Lua は初めてで、キャラクターの動きをシミュレートしようとしています。現在、キャラクターを左右に動かしています。キャラクターを一度に 16 ピクセルずつ動かしたいと考えています。ユーザーが電話にすばやく触れないことを考えると、これはうまく機能します。その場合、キャラクターはランダムな数のピクセルを移動します。
私の質問は、タッチ イベントを一度に 1 回だけ登録するにはどうすればよいかということです。
私のコード:
-- move character
function moveCharacter(event)
if event.phase == 'began' then
if event.x > character.x+8 then
transition.to(background, {time=800, x=background.x-16})
end
if event.x < character.x-8 then
transition.to(background, {time=800, x=background.x+16})
end
end
end
function touchScreen(event)
Runtime:removeEventListener('touch', moveCharacter)
if event.phase == 'began' then
Runtime:addEventListener('touch', moveCharacter)
end
end
Runtime:addEventListener('touch', touchScreen)