Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
problem between two scenes — Gideros Forum

problem between two scenes

shadowlordDEAshadowlordDEA Member
edited September 2012 in Game & application design
hello guys!
I'm using the "SceneManager" to switch between scenes.
On the first screen, I have a menu with four options:
new game
continue
options,
exit.
when I click "options"
Scene manager switches to the options screen.
The problem is that when I click on a blank area in the options screen, it recognizes the click button on the first screen.
And as if the button was working but invisible.

How do I remove the objects from the first screen?
If I remove the objects, I can return it when clicking the back button of the options screen? :)>-

Comments

  • MellsMells Guru
    edited September 2012
    Hi @shadowlordDEA,
    How do I remove the objects from the first screen?
    I remove event listeners on exitBegin :

    We have 4 events dispatched to the scene sprites added to Scene Manager, these are:

    - 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.

    - exitBegin: Dispatched when your current scene is about to leave the stage. You can remove listeners and stop timers here.

    - exitEnd: Dispatched after your current scene has leaved the stage.

    [ More informations ]

    and it looks like this in my projects (this is just my way to do, probably can be improved) :
     
    function MyScene:init()		
            -- --------------------------------------
    	-- SCENE EVENTS
    	-- --------------------------------------
    	-- Here I group scene related Events
            self:addEventListener("enterBegin", self.onEnterBegin, self)
    	self:addEventListener("enterEnd", self.onEnterEnd, self)
    	self:addEventListener("exitBegin", self.onExitBegin, self)
    	self:addEventListener("exitEnd", self.onExitEnd, self)
     
    end
     
     
    function MyScene:onEnterEnd()
          -- Here I add other listeners, objects, etc
          self:addEventListener(Event.MOUSE_DOWN, self.goToNextPage, self)	
    end
     
    (...)
     
    function MyScene:onExitBegin()
            -- Here I remove listeners that I have added from onEnterEnd until onExitBegin
    	self:removeEventListener(Event.MOUSE_DOWN, self.goToNextPage, self)	
    end
     
    function MyScene:onExitEnd()
     
    	-- --------------------------------------
    	-- SCENE EVENTS
    	-- --------------------------------------
            -- And finally I remove scene event listeners
    	self:removeEventListener("enterBegin", self.onEnterBegin, self)
    	self:removeEventListener("enterEnd", self.onEnterEnd, self)
    	self:removeEventListener("exitBegin", self.onExitBegin, self)
    	self:removeEventListener("exitEnd", self.onExitEnd, self)
     
            collectgarbage()
            collectgarbage()
            collectgarbage()
            collectgarbage()
    end
    I do like this to be sure about what is removed and when.
    Also, all your event listeners will be added the next time you enter that scene again.

    I am not sure that it's the best way to do it, other devs will probably come up with improvements and/or alternatives.

    Question : are you sure that the listener that is .... listening... was added to the "first screen"? Are you sure that it was not added to the stage, the scene controller or another entity that is accessible globally?
    After exiting the first screen, in theory it should have been automatically removed unless I mistake and somebody will correct me.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • Thank Mells.
    You helped me a lot.
    I was doing wrong was not putting the code "inside" of the events.
  • MellsMells Guru
    Accepted Answer
    Glad I could help.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.