Hi community,
I am wondering what would be the case where it makes a difference.
For example, the docs say :
enterBegin: Dispatched when your new scene is about to enter the stage. You can initialize your variables here.
enterEnd: Dispatched after the transition of new scene has ended. Mostly, you add listeners and start your logic here.
Until now I used to initialiaze my variables in Scene:init() and from there I call for example :
- Scene:createMenu() where I create the menu (add Buttons and event listeners)
- Scene:addPlayer() where all things about the Player would happen
I am trying to better organize my code and be sure to keep track of all timers, event listeners.
So :
- What would be the benefit for me to modify my code and use Events like "onEnterBegin", "onEnterEnd"?
- What would be a clear case where the separation of my code between onEnterBegin and onEnterEnd would make a clear difference
Thank you
Comments
Here's a copy of my scene template file.
Likewise in the exitSceneStart() function I disable all widgets / controls etc for the same reason and then in the exitSceneEnd() function I remove / destroy any non-permanent resources allocated during enterSceneStart().
That structure helps to keep my code neat and tidy and means that I don't forget to release resources, leak memory etc.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Those informations will probably be helpful for a lot of new users of Gideros.
I'm back to work and will implement those changes.