2016-08-08 4 views
0

これは、これはタイマーがまだコンソールにものを印刷している、私は(シーンを離れる前に)タイマーをキャンセルするが、私は現場を去るとき、彼らはまだそこにあるかである私は、タイマーを起動する方法corona sdkのシーン非表示イベントが発生しないのはなぜですか?シーンを削除してもタイマがコンソールに何かを印刷しているのはなぜですか?

local composer = require("composer") 
local scene = composer.newScene() 

timersArray = {} 

function scene:create(event) 

    function performTimedEvents(timeString) 

    local function onTimer(event) 
     local params = event.source.params 
     if(arg == 5) then 
     timer.cancel(event.source) 
     return 
     end 
    end 

    for i=1,10 do 
     --print("performWithDelay "..sliceStars(timeString)[i]) 
     timersArray[i] = timer.performWithDelay(1000*sliceStars(timeString)[i], onTimer) 
     timersArray[i].params = { n = i } 
    end 

    end 

    performTimedEvents(pagesTimers[currentPage]) 
end 

です。私たちは、出口で絵コンテいたが、この非表示のコールバックが呼び出さなっていないときに非表示に解雇されていない、それは昔で働いていた、助けてください..この特定の行のシーンは、なぜまたtimer.cancel(timersArray[j])

function flushTimers() 
    pageSequence(5) 
    print("QQQtimersArray") 
    print_r(timersArray) 
    for j=1,#timersArray do 
    print("didCancelTimer "..j) 
    timer.cancel(timersArray[j]) 
    --timer.pause(timersArray[j]) 
    timersArray[j] = nil 
    end 
    timersArray = {} 
    print_r(timersArray) 
    print("didReturn"); 
end 

に気づきます: (

道による
function scene:hide(event) 

print("YYY_hide_!!!") 

local sceneGroup = self.view 
local phase = event.phase 



if (phase == "will") then 
    print("YYY_hide_will") 
    -- Called when the scene is on screen (but is about to go off screen) 
    -- Insert code here to "pause" the scene 
    -- Example: stop timers, stop animation, stop audio, etc. 
elseif (phase == "did") then 
    print("YYY_hide_did") 
    -- Called immediately after scene goes off screen 
end 
end 

function scene:destroy(event) 

local sceneGroup = self.view 

-- Called prior to the removal of scene's view 
-- Insert code here to clean up the scene 
-- Example: remove display objects, save state, etc. 

--myAudioPlayer = nil 
--audio.stop() 
--audio.rewind(1) 
flushTimers() 
--timersArray = nil 

print("YYY_destroy_did") 
end 


scene:addEventListener("create", scene) 
scene:addEventListener("show", scene) 
scene:addEventListener("hide", scene) 
scene:addEventListener("destroy", scene) 

が、これは私が位相がシーン内でやっているとき、あなたはあなたのタイマーをキャンセルしなければならない現在のシーン

 composer.removeScene("currentScene") 
     composer.gotoScene("nextScene",effectOptions) 

答えて

1

を削除する方法である:非表示()イベント。

function scene:hide(event) 

    print("YYY_hide_!!!") 

    local sceneGroup = self.view 
    local phase = event.phase 

    if (phase == "will") then 
     print("YYY_hide_will") 
     -- Called when the scene is on screen (but is about to go off screen) 
     -- Insert code here to "pause" the scene 
     -- Example: stop timers, stop animation, stop audio, etc. 
    elseif (phase == "did") then 
     print("YYY_hide_did") 
     -- Called immediately after scene goes off screen 
     flushTimers() 
     composer.removeScene("sceneName") 
    end 
end 
+0

私は本当にあなたの答えに感謝しますが、このイベントは:( 「印刷( 『YYY_hide _を!!!』)」発射されていませんがalltogether印刷取得されていない、私は本当にこの問題でサポートが必要な、私は私ができることを願います今日は賞金を払ってください。しかし、できるようになるには2日が必要です。 – DeyaEldeen

関連する問題