Just note that fxEnded ends *after* changeScene().
This can bring many complications if passed unnoticed.
Thanks again for sharing! [import]uid: 7356 topic_id: 2447 reply_id: 10729[/import]
Just note that fxEnded ends *after* changeScene().
This can bring many complications if passed unnoticed.
Thanks again for sharing! [import]uid: 7356 topic_id: 2447 reply_id: 10729[/import]
Magenda
You are right! All that clean up commands should be at fxEnded. I’ll change it and post again soon. Thanks! [import]uid: 8556 topic_id: 2447 reply_id: 10756[/import]
Hey ricardorauber,
you are my hero!
Thanks a million for this.
[import]uid: 9371 topic_id: 2447 reply_id: 11513[/import]
Thanks dweezil!
I putted some important content in the http://developer.anscamobile.com/code/director-class-10 [import]uid: 8556 topic_id: 2447 reply_id: 11524[/import]
What should I do about freeing listeners created in each screen?
[import]uid: 9371 topic_id: 2447 reply_id: 11535[/import]
dweezil
You can create a function that removes all the listeners and when you call the changeScene, call this clean function first.
Future releases may control it for you, stay tuned. [import]uid: 8556 topic_id: 2447 reply_id: 11563[/import]
SO I now have…
local function bt01t ( event )
if event.phase == “ended” then
cleanUP()
director:changeScene(“screen1”,“moveFromBottom”)
end
end
and…
local function cleanUP()
bt01:removeEventListener(“touch”,bt01t)
soccerball:removeEventListener(“touch”, movesoccerball)
soccerball1:removeEventListener(“touch”, movesoccerball1)
soccerball:removeEventListener(“collision”, soccerball)
soccerball1:removeEventListener(“collision”, soccerball1)
end
But now the event for the bt01 button is not fired. Why? [import]uid: 9371 topic_id: 2447 reply_id: 11599[/import]
Have your clean() function be a global one and only call it from within director inside fxEnded. [import]uid: 7356 topic_id: 2447 reply_id: 11602[/import]
But how will I then know which listeners to clear? [import]uid: 9371 topic_id: 2447 reply_id: 11606[/import]
Just trying to understand the logic/flow of the director class.
So each time a new screen is transitioned to all the variables and objects of that screen are getting created each time?
If so then the clean routine has to remove all objects and nullify the local variables>? [import]uid: 9371 topic_id: 2447 reply_id: 11752[/import]
Also tried the
package.loaded[lastScene].clean()
and added an empty clean function to each screen but transitioning from screens doesn’t work [import]uid: 9371 topic_id: 2447 reply_id: 11753[/import]
dweezil
First let me answer your question about which listeners to clear. If you take a look at the asnca roadmap, you’ll find that corona will have a table of active timers. That was one of the issues that I created and with that, Director will clean all active timers. Today, Director can only clean display objects and their listeners, so you have to clean Runtime listeners and timers.
Now let’s talk about the logic of the Director class. It’s very simple, I created it because before it corona didn’t have any kind of changing control for multiple files, all development were 90% in the main.lua file. The idea was to build something that makes possible to use different files for different levels for a game. So, it was build thinking on cleanning everything of the old screen and adding all of the new screen. Director’s changeScene tests if is the same screen, then choose the effect and start to clean all objects inserted in the view. After that, it loads the new file and do the garbage collect to clean memory.
About the package.loaded[lastScene].clean(), any error could stop the transitions. For that, the best to do is take the errors and make a debug (maybe using the print() function) or you can put it here and we try to help you. [import]uid: 8556 topic_id: 2447 reply_id: 11755[/import]
It might have helped if I had declared the clean function without the local keyword! DOH!!! [import]uid: 9371 topic_id: 2447 reply_id: 11756[/import]
Next problem. Now I’ve added…
local function crossBar(event)
print(“crossBar()”)
end
timer.performWithDelay(1000, crossBar, 0)
…to my game screen but the screen now scrolls off the screen during the transition. Any ideas why? [import]uid: 9371 topic_id: 2447 reply_id: 11757[/import]
Your timer will print “crossBar()” forever with that. You have to create a variable to control it and cancel the timer while changing the scene.
Something like this:
local function crossBar(event)
if sceneChanged then
timer.cancel(self)
else
print("crossBar()")
end
end
timer.performWithDelay(1000, crossBar, 0)
[import]uid: 8556 topic_id: 2447 reply_id: 11758[/import]
Where is sceneChanged defined? [import]uid: 9371 topic_id: 2447 reply_id: 11759[/import]
You can put it at the beginning of your file an use all over it. [import]uid: 8556 topic_id: 2447 reply_id: 11760[/import]
In the main.lua?
Could you show me some code?
I still don’t quite understand why it would cause the images would be scrolled off the screen.
What I’m trying to achieve is to move a game object after 20 seconds of time. [import]uid: 9371 topic_id: 2447 reply_id: 11761[/import]
dweezil
Maybe you are not looking for the code that’s doing what you are talking about. It will be much easier if you put your code here. [import]uid: 8556 topic_id: 2447 reply_id: 11762[/import]
Can I email you the source? [import]uid: 9371 topic_id: 2447 reply_id: 11763[/import]