cocos2d 启动/停止运行场景 [英] cocos2d start / stop running Scene
问题描述
我正在尝试加载一个场景.第一次运行良好,但是当我再次尝试重新加载时,会出现一个放置动画的白色方块.
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?
谢谢.
-(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];
}
推荐答案
为什么不在 stopScene
的末尾调用 [self runScene]
而不是 [[CCDirector sharedDirector] pushScene:scene]
?听起来您希望场景重新加载新鲜,您的 runScene
在调用 replaceScene
时已经这样做了.
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
.
无论哪种方式,您都应该创建一个新的场景节点并使用 replaceScene
(这是在 runScene
中完成的,这就是我建议只调用它的原因).
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).
这篇关于cocos2d 启动/停止运行场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!