Cocos2D Director暂停/恢复问题
我正在尝试在 cocos2D 中播放 .gif 动画。为此,我使用库 glgif。现在,为了显示动画,我暂停了Director,添加了一个子视图来显示动画,动画完成后我将恢复Director。 但是,我无法恢复Director的状态,它显示为空白。 所以我在没有暂停和恢复这个导演的情况下尝试了这个,但它仍然不起作用。我还尝试在动画之前分离导演并在之后将其添加回来,即使这样也不起作用。
那么有没有办法在应用程序中暂停/暂停Director并正确恢复回来呢?
谢谢。
代码示例:
[[Director sharedDirector] pause];
[[Director sharedDirector] detach];
AppDelegate *del = [[UIApplication sharedApplication] delegate];
[del.window addSubview:del.viewController.view];
[del.window makeKeyAndVisible]; // this is code to call glgif class and start anim.
//code to resume the director
AppDelegate *del = [[UIApplication sharedApplication] delegate];
[[Director sharedDirector] resume];
[[Director sharedDirector] attachInView:del.window];
MScene *m = [MScene node];
[[Director sharedDirector] replaceScene:m];
I am trying to play a .gif animation in cocos2D. For this i am using the library glgif. Now, to display the animation i am pausing the Director, adding a subview to show the animation and after the animation is done i am resuming the Director.
However, I am not able to resume the state of the Director and it shows blank.
So I tried this without pausing and resuming this Director and it still did not work.I also tried detaching the director before tha animation and adding it back afterwards and even that did not work.
So is there a way to pause/suspend the Director in the application and properly restore is back?
Thanks.
Code sample:
[[Director sharedDirector] pause];
[[Director sharedDirector] detach];
AppDelegate *del = [[UIApplication sharedApplication] delegate];
[del.window addSubview:del.viewController.view];
[del.window makeKeyAndVisible]; // this is code to call glgif class and start anim.
//code to resume the director
AppDelegate *del = [[UIApplication sharedApplication] delegate];
[[Director sharedDirector] resume];
[[Director sharedDirector] attachInView:del.window];
MScene *m = [MScene node];
[[Director sharedDirector] replaceScene:m];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它是一个简单的覆盖,只需暂停并直接执行 UIKit 调用即可。像这样:
如果您确实要接管整个窗口,则完全处理它
并重做初始化并在返回时调用 runWithScene 。分离/附加舞蹈似乎效果不佳或不一致。
If it's a simple overlay, just pause and do your UIKit calls directly. Like this:
If you're really taking over the whole window, then dispose of it completely
and redo your intialization and call runWithScene when you go back. The detach/attach dance does not seem to work well or consistently.
您的一些错误可能是由于附加/分离、显示/隐藏视图造成的。我和我的团队只在
applicationDidFinishLoading
上调用attachInView
一次,如果我们想在 Cocos 之上的其他视图中进行更改,我们使用sendToBack
或bringToFront
调用委托窗口实例。可能值得一试。让我知道这是否有意义,或者如果没有,我可以添加一些示例代码。Its possible some of your errors are as a result of attach/detaching, showing/hiding views. Me and my team only call
attachInView
once onapplicationDidFinishLoading
and if we want to change in other views over top of Cocos we usesendToBack
orbringToFront
calls on the delegate window instance. Might be worth a shot. Let me know if that makes sense or if not I can toss in some sample code.不完全确定它是否可以在这里提供帮助,但值得一提的是:CCDirector 暂停方法不会完全停止动画,而只是减慢动画速度。 StopAnimation 方法完全停止它。所以也许 stopAnimation/startAnimation 而不是暂停/恢复可以解决这个问题。
Not completely sure if it could help here, but it is worth mentioning: CCDirector pause method does not stop animation completely but just slows it. StopAnimation method completely stops it. So maybe stopAnimation/startAnimation instead pause/resume could solve this problem.