cocos2d启动/停止运行场景
我正在尝试加载一个场景。第一次运行良好,但是当我尝试再次重新加载时,会在放置动画的地方出现一个白色方块。
这是启动和停止场景的代码。我缺少什么?
谢谢。
-(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];
}
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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不在
stopScene
末尾调用[self runScene]
而不是[[CCDirector sharedDirector] PushScene:scene]
?听起来您希望场景重新加载新鲜,您的runScene
在调用replaceScene
时已经这样做了。无论哪种方式,您都应该创建一个新的场景节点并使用
replaceScene
(这是在runScene
中完成的,这就是为什么我建议只调用它)。Why not just call
[self runScene]
at the end ofstopScene
rather than[[CCDirector sharedDirector] pushScene:scene]
? It sounds like you want the scene to reload fresh, which yourrunScene
already does when it callsreplaceScene
.Either way you should be creating a new scene node and using
replaceScene
(which is being done inrunScene
and is why I recommend just calling that).