Jonny
Jonny

Reputation: 16328

Issue with transitions between scenes using effects

I've ran into a (hard to catch) issue using transitions between scenes in Cocos2d-x.

Basically I normally do a fade in-fade out like this:

Director::getInstance()->replaceScene(TransitionFade::create(0.5, scene, Color3B(0, 0, 0)));

It looks visually good and proper and all but I realized that it can be dangerous. If I have a button to go from Scene A to Scene B this way, the transition will run for 0.5 seconds as per the above implementation. When tapping ONCE and waiting, everything will be fine but if you tap very fast, it IS possible to have the event of the button called another time, even though the first transition call is already under way. This can, and I think in my case, lead to all sorts of strange and dangerous things. Especially for me who often use a protocol/delegate pattern for fetch data callbacks etc.

Want we want to do is to disable any UI (at least, possibly more?) on scene A as soon as the transition starts just to be sure that no other pushes are possible to the same or any other button, causing more transitions to be launched which could cause harmful things. Or there should be some kind of feature within cocos2d-x to always refuse transitions if one transition is already under way... To me that sounds like the most sane thing at first thought.

Is there anything I missed or are transitions in cocos2d-x really this dangerous? Anyone tackled this? Maybe a way to check if a transition is already under way would be one way for me to get around this problem without hacking around on cocos2d-x itself?

Upvotes: 0

Views: 464

Answers (1)

Aaron Baumbach
Aaron Baumbach

Reputation: 161

The virtual cocos2d::Node function onEnterTransitionDidFinish() could be used to unregister your callbacks for web requests etc.

Assuming you don't use the cocos2d-x event system for any app logic during a transition you might also consider disabling the EventDispatcher to block the propagation of touch events.

You could simply disable the button after it triggers.

Or you could be super lazy and create a Layer/TouchListener to intercept touch when a transition begins (onEnterTransitionDidStart()), and destroy it along with your scene :)

Upvotes: 1

Related Questions