好吧,所以我有一個跳轉按鈕和一個運行時監聽器功能,當按下跳轉按鈕時。 所以當按下跳轉按鈕時,我會將線性衝動應用於遊戲英雄。如何防止遊戲中無限跳躍?電暈LUA
local function controls(event)
if(event.phase=="began") then
if (buttonpressed.id=="jump") then
hero:applyLinearImpulse(0,-10,hero.x,hero.y)
end
elseif(event.phase=="ended") then
end
end
現在問題是,如果用戶不斷點擊跳轉按鈕,然後英雄不斷上升。我不能想到反對這一點。有一件事我可以做的是上面的代碼更改爲:
local function controls(event)
if(event.phase=="began") then
if (buttonpressed.id=="jump" and hero.y>display.contentHeight/2) then
hero:applyLinearImpulse(0,-10,hero.x,hero.y)
end
elseif(event.phase=="ended") then
end
end
但這將仍然允許跳躍按鈕的工作達到一半的屏幕,直到。 請幫助我。
感謝