Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Stopping events during scene transitions w/ scene manager — Gideros Forum

Stopping events during scene transitions w/ scene manager

ndossndoss Guru
edited April 2012 in Code snippets
Problem: During scene transitions, both the source and destinations scenes are active. This can cause problems for some applications since it's possible to interact with the scenes during the transition.

The fix we came up with was to:
1. add a handler for the scene manager transitionBegin event that adds a sprite to the stage that catches events that we care about and stops them from propagating
2. add a handler for the scene manager transitionEnd event that removes the sprite from the stage and removes the event listener

Is this a good approach? Is there a better way to handle this problem?

Here's the code we're currently using to stop MOUSE_DOWN events during transitions:
local transitionEventCatcher = Sprite.new()
 
local function stopTransitionEvents(e)
   e:stopPropagation()
end
 
local function onTransitionBegin()
   stage:addChild(transitionEventCatcher)
   transitionEventCatcher:addEventListener(Event.MOUSE_DOWN, stopTransitionEvents)
end
 
local function onTransitionEnd()
   transitionEventCatcher:removeEventListener(Event.MOUSE_DOWN, stopTransitionEvents)
   stage:removeChild(transitionEventCatcher)
end
 
sceneManager:addEventListener("transitionBegin", onTransitionBegin)
sceneManager:addEventListener("transitionEnd",   onTransitionEnd)

Likes: avo, red032

+1 -1 (+2 / -0 )Share on Facebook

Comments

  • avoavo Member
    edited April 2012
    I think I understand the problem you had, but isn't this what exitBegin/enterEnd are for? They are dispatched at the same time.

    exitBegin to stop the listeners on one scene and enterEnd to start them on the next one?

    edit: sorry I meant exitBegin/enterBegin and exitEnd/enterEnd are at the same time
  • ndossndoss Guru
    edited April 2012
    I think I understand the problem you had, but isn't this what exitBegin/enterEnd are for? They are dispatched at the same time.
    Yes, it looks like transitionBegin, exitBegin, enterBegin are equivalent and are dispatched at the same time (same for transitionEnd, exitEnd, enterEnd). (EDIT: I guess they're not totally equivalent since the first transition after startup doesn't emit exit* events)
    exitBegin to stop the listeners on one scene and enterEnd to start them on the next one?
    That's what I think I'm doing that w/ this example code -- it's just not specific to a particular scene? Did you mean something else?
  • avoavo Member
    No I guess I just didn't understand fully afterall. I was thinking more specific scene to scene clearing things out etc. I actually really like how you did this as a "universal pause" for mouse events.


  • I know when you do certain animations on iOS that touches are disabled until the end of the animation. I doubt Gideros does that but adding a full screen sprite sounds like a good workaround to me.
Sign In or Register to comment.