2011-04-23 46 views
2

如何對水龍頭功能中的電暈進行連續動作?我的意思是,當event.phase="began",直到它的挖掘行動重複,直到它結束。如何對水龍頭功能進行連續動作

我的代碼:

function upArrowtap(event) 
    if (event.phase == "began") then 
    if (ball.y > 45) then 
     transition.cancel(trans1) 
     transition.cancel(trans2) 
     --ball.y = ball.y-15 
     start() 
    end 
    end 
end 

upArrow:addEventListener("touch", upArrowtap) 

希望你明白我的問題。

+0

先生我用這 – 2011-04-23 13:24:47

+0

功能upArrowtap(事件) 如果(event.phase == 「開始」),然後 如果(ball.y> 45),那麼 transition.cancel(反-1) transition.cancel(TRANS2 ) - ball.y = ball.y-15 的start() 結束 結束 結束 UPARROW:的addEventListener( 「觸摸」,upArrowtap) – 2011-04-23 13:25:25

回答

8

首先,使用事件偵聽器來「觸摸」而不是「點擊」。輕按事件偵聽器僅在手指被移除時作出響應,但觸摸偵聽器會響應觸摸的開始和結束。

其次,要讓事件一遍又一遍地重複,您需要使用enterFrame。觸摸開始時那麼設置一個enterFrame事件偵聽器,當觸摸結束移除enterFrame事件監聽器:

local function onEnterFrame(event) 
    ball.y = ball.y + 2 
end 
local function onTouch(event) 
    if (event.phase == "began") then 
    Runtime:addEventListener("enterFrame", onEnterFrame) 
    elseif (event.phase == "ended") then 
    Runtime:removeEventListener("enterFrame", onEnterFrame) 
    end 
end 
button:addEventListener("touch", onTouch) 

(我可能已經接到了幾個關鍵字錯了,我剛纔輸入的是把我的頭頂部)

+0

先生你能提供給我一個簡單的代碼例子... – 2011-04-23 13:23:31

+0

非常感謝先生。謝謝它的完美... – 2011-04-23 13:58:55