Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
What would be the case where 'something' should be done onEnterEnd instead of onEnterBegin? — Gideros Forum

What would be the case where 'something' should be done onEnterEnd instead of onEnterBegin?

MellsMells Guru
edited August 2012 in General questions
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 :
  1. What would be the benefit for me to modify my code and use Events like "onEnterBegin", "onEnterEnd"?
  2. What would be a clear case where the separation of my code between onEnterBegin and onEnterEnd would make a clear difference
Thank you
twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    I'd say it only changes if you want your objects to be seen on scene during the transition. Or only appear after scene transition is completed.
  • techdojotechdojo Guru
    Accepted Answer
    In my scene manager code I have four callback handlers setup which are fired during the scene transition phase.

    Here's a copy of my scene template file.
    SceneTemplate = Core.class(Sprite)
     
     
    -- Called when the scene is first created.
    function SceneTemplate:init( data )	
    end
     
    -- Called once per frame when the scene is active
    function SceneTemplate:onUpdate( data )		
    end
     
    -- Called BEFORE scene has moved onscreen (before the transition starts)
    function SceneTemplate:enterSceneStart( data ) 
    	--print("SceneTemplate:enterSceneStart")
    end
     
    -- Called immediately after scene has moved onscreen (when the transition ends)
    function SceneTemplate:enterSceneEnd( data ) 
    	--print("SceneTemplate:enterSceneEnd")
    end
     
    -- Called when scene is about to move offscreen (before the transition starts)
    function SceneTemplate:exitSceneStart( data ) 
    	--print("SceneTemplate:exitSceneStart")
    end
     
    -- Called AFTER scene has finished moving offscreen (when the transition ends)
    function SceneTemplate:exitSceneEnd( data ) 
    	--print("SceneTemplate:exitSceneEnd")
    end
     
    -- Called prior to the removal of a scene (after a purge/remove scene call - free up all resources)
    function SceneTemplate:destroyScene( data ) 
    	--print("SceneTemplate:destroyScene")
    end
    -- End of file...
    I use the enterSceneStart() function to create / initialise any screen components / widgets etc so they are ready before the scene transitions in. I use the enterSceneEnd() function to activate the widgets so you can't do silly things like press buttons or change tabs during the transition phase.

    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.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • Thank you, it makes a lot of sense.
    Those informations will probably be helpful for a lot of new users of Gideros.

    I'm back to work and will implement those changes.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.