how to put functions in to scene groups
Even though you can attach a function to a displayGroup like this:
local dg = display.newGroup() dg.func = function() print("Hello") end dg.func()
You should be asking yourself why.
I would add the functions to the scene or if I use them frequently add them to a new Lua file and include that file in the different scenes.
Best regards,
Tomas
Why would you need to do that? I have never needed to do that… Maybe you are having a problem? Like the function isnt stopping when the scene changes? If so then you have to cancel the timer that is starting that function of remove the eventListener?
Good Luck!
how do i remove a event listener
this is the code i would not want on all the scenes
[lua]
local secondsLeft = 20 * 60
local clockText = display.newText(“20:00”, 160,30)
local function updateTime()
secondsLeft = secondsLeft - 10
local minutes = math.floor( secondsLeft / 60)
local seconds = secondsLeft % 60
local timeDisplay = string.format("%02d:%02d", minutes, seconds)
clockText.text = timeDisplay
if timeDisplay == “18:00” then
composer.gotoScene(“menu”)
end
end
local countDownTimer = timer.performWithDelay(1000, updateTime, secondsLeft)
[/lua]
Object:removeEventListener( “touch,collision, ect”, function )
timer.cancel(timerName)
so how would i write that with the code above
I don’t see any listeners… So do
timer.cancel(countDownTimer)
doesn’t seem to be working do you know any other way of making a timer
Even though you can attach a function to a displayGroup like this:
local dg = display.newGroup() dg.func = function() print("Hello") end dg.func()
You should be asking yourself why.
I would add the functions to the scene or if I use them frequently add them to a new Lua file and include that file in the different scenes.
Best regards,
Tomas
Why would you need to do that? I have never needed to do that… Maybe you are having a problem? Like the function isnt stopping when the scene changes? If so then you have to cancel the timer that is starting that function of remove the eventListener?
Good Luck!
how do i remove a event listener
this is the code i would not want on all the scenes
[lua]
local secondsLeft = 20 * 60
local clockText = display.newText(“20:00”, 160,30)
local function updateTime()
secondsLeft = secondsLeft - 10
local minutes = math.floor( secondsLeft / 60)
local seconds = secondsLeft % 60
local timeDisplay = string.format("%02d:%02d", minutes, seconds)
clockText.text = timeDisplay
if timeDisplay == “18:00” then
composer.gotoScene(“menu”)
end
end
local countDownTimer = timer.performWithDelay(1000, updateTime, secondsLeft)
[/lua]
Object:removeEventListener( “touch,collision, ect”, function )
timer.cancel(timerName)
so how would i write that with the code above
I don’t see any listeners… So do
timer.cancel(countDownTimer)
doesn’t seem to be working do you know any other way of making a timer