问题
I'm trying to load one scene. This runs fine the first time, but when I try to reload again appears a white square where the animation is placed.
This is the code to start and stop the scene. What I'm missing?
thanks.
-(void)runScene:(OTAnimationCC2d *)animation
{
scene = [CCScene node];
[scene addChild:animation];
if ([[[CCDirector sharedDirector] runningScene] isRunning])
{
[[CCDirector sharedDirector] replaceScene:scene];
}
else
{
[[CCDirector sharedDirector] runWithScene:scene];
}
}
-(void)stopScene
{
[[[CCDirector sharedDirector] runningScene] stopAllActions];
[[[CCDirector sharedDirector] runningScene] removeAllChildrenWithCleanup:YES];
[[CCDirector sharedDirector] pushScene:scene];
}
回答1:
Why not just call [self runScene]
at the end of stopScene
rather than [[CCDirector sharedDirector] pushScene:scene]
? It sounds like you want the scene to reload fresh, which your runScene
already does when it calls replaceScene
.
Either way you should be creating a new scene node and using replaceScene
(which is being done in runScene
and is why I recommend just calling that).
来源:https://stackoverflow.com/questions/9418791/cocos2d-start-stop-running-scene