重新加载相同的 cocos2d 场景显示粉红色屏幕
我正在cocos2d 中制作游戏。游戏场景有一个菜单按钮可以返回主菜单,它是一个 UIViewController。当用户选择再次玩游戏并调用相同的游戏场景在director中运行时,游戏场景顶部会出现粉红色屏幕。
可能是因为用自己替换了相同的场景。因此,当调用主菜单时,我首先将其替换为空场景。替换场景的代码是:
if ([[CCDirector sharedDirector] runningScene] == NULL) {
[[CCDirector sharedDirector] runWithScene: [MySceneLayer scene]];
}
else {
[[CCDirector sharedDirector] replaceScene:[MySceneLayer scene]];
}
它检查,如果没有场景正在运行,则第一次启动游戏场景。如果某个场景已在运行(在本例中为空场景),则将其替换为游戏场景。游戏场景的dealloc也被称为,这意味着旧场景被正确销毁。即使如此,用游戏场景替换空场景也会出现粉红色屏幕,而用任何其他新场景替换则不会出现任何问题。
可能是什么原因以及解决方案是什么?
I am making a game in cocos2d. Game Scene has a menu button to take back to main menu which is a UIViewController. When user chooses to play again and same game scene is called to run in director, a pink screen appears on top of game scene.
It could be because of replacing the same scene with itself. So, I replaced it with an empty scene first when main menu is called. Code replacing scene is:
if ([[CCDirector sharedDirector] runningScene] == NULL) {
[[CCDirector sharedDirector] runWithScene: [MySceneLayer scene]];
}
else {
[[CCDirector sharedDirector] replaceScene:[MySceneLayer scene]];
}
It checks, if there is no scene running then starts the game scene first time. If some scene is already running, which in this case is an empty scene, then replaces it with game scene. The dealloc of game scene is also called which means that old scene is destroyed properly. Even then, replacing empty scene with game scene gives pink screen while replacing with any other new scene does not give any problem.
What can be the reason and what is the solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,问题被抓住并解决了。它所需要的只是小心地添加和删除视图。返回 UIViewController 中的菜单时,我正在从超级视图中删除 OpenGLView。再次替换场景时,
必须将之前使用的相同场景添加回应用程序窗口。正确的地点和正确的时间做到了。
视图或精灵中的任何小错误都可能会显示粉红色屏幕:)
Finally, the problem caught and resolved. All it needs is careful play of adding and removing views. I was removing OpenGLView from superview when coming back to menu in UIViewController. While replacing the scene again, same
which was in use earlier, had to be added back to the application window. Right place and right timing did it.
Any minor error in views or sprites can show you with pink screen :)