iPhone - 从视图控制器启动cocos2d场景,从场景内关闭
我该怎么做?
在我的 UIViews(nib 文件)之一上,我有 ImageView 和一个启动全屏 Cocos2d 场景的按钮。在该场景中,我想关闭它并返回到 UIView,以便用户稍后可以再次打开场景,但可以从 ImageView 中的不同图像(并且场景上具有不同的内容)。
然而,在我第一次“关闭”场景后,整个应用程序对所有触摸事件的反应要慢得多。只要场景打开,它就可以快速运行,但是当场景关闭时,性能就会下降。
我应该如何正确关闭场景以便再次重新启动它?我浏览了很多代码示例,到处都是 replaceWithScene:newScene
。
How do I do this?
On one of my UIViews (nib file) I have ImageView and a Button that starts full screen Cocos2d scene. From within that scene I want to close it and go back to UIView, so that user can later open the scene again but from different image in ImageView (and with different content on scene).
However, after the first time I "close" the scene the whole app reacts a lot slower to all touch events. It works fast as long as the scene is on, but when closed then performance goes down.
How should I properly close the scene so that I can restart it again? I've browsed through a lot of code samples and everywhere is just replaceWithScene:newScene
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 UIView 添加到包含正在运行的 openGL 层的 viewController 会减慢应用程序的速度,任何尝试将 UIScrollView 合并到 Cocos2D 游戏中的人都可以告诉您。您将关闭场景,但可能不会停止 CCDirector,CCDirector 现在除了应用程序的调度程序之外还运行自己的调度程序。当它们争夺 CPU 的主导地位时,OpenGL 总是获胜,因为它更频繁地需要更多的功能。
确保您完全关闭 cocos2D 和 OpenGL。即使只调用[[CCDirector共享导演]暂停]。
Adding a UIView to a viewController that houses a running openGL layer slows the app, as anyone who has tried to incorporate a UIScrollView into a Cocos2D game can tell you. You are closing the scene, but likely not stopping the CCDirector, which is now running its own scheduler aside the application's scheduler. As they fight for dominance over the CPU, OpenGL invariably wins as it needs more power more often.
Ensure you are completely shutting down cocos2D and OpenGL. Even if only calling [[CCDirector sharedDirector] pause].