From 439640ff7c8d6ad3a6c6edc321468e9bb48f8561 Mon Sep 17 00:00:00 2001 From: Fabian Inthamoussu Date: Wed, 13 Jan 2016 09:43:45 -0300 Subject: [PATCH] FIX CCDirector's popToRootSceneWithTransition (running scene onExitTransitionDidStart and onExit where called twice) --- cocos2d/CCDirector.m | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cocos2d/CCDirector.m b/cocos2d/CCDirector.m index bb2bf76bc78..dd21b1db210 100644 --- a/cocos2d/CCDirector.m +++ b/cocos2d/CCDirector.m @@ -594,12 +594,14 @@ -(void) popToRootScene } -(void) popToRootSceneWithTransition:(CCTransition *)transition { - [self popToRootScene]; - _sendCleanupToScene = YES; - [transition startTransition:_nextScene]; + [self popToSceneStackLevel:1 withTransition:transition]; } --(void) popToSceneStackLevel:(NSUInteger)level +-(void) popToSceneStackLevel:(NSUInteger)level { + return [self popToSceneStackLevel:level withTransition:nil]; +} + +-(void) popToSceneStackLevel:(NSUInteger)level withTransition:(CCTransition *)transition { NSAssert(_runningScene != nil, @"A running Scene is needed"); NSUInteger c = [_scenesStack count]; @@ -617,7 +619,7 @@ -(void) popToSceneStackLevel:(NSUInteger)level // pop stack until reaching desired level while (c > level) { CCScene *current = [_scenesStack lastObject]; - if( current.runningInActiveScene ){ + if( current.runningInActiveScene && transition == nil ){ [current onExitTransitionDidStart]; [current onExit]; } @@ -627,7 +629,10 @@ -(void) popToSceneStackLevel:(NSUInteger)level c--; } _nextScene = [_scenesStack lastObject]; - _sendCleanupToScene = NO; + _sendCleanupToScene = transition != nil; + if (transition) { + [transition startTransition:_nextScene]; + } } // -----------------------------------------------------------------