当我们应该使用pushScene和replaceScene? [英] When we should use pushScene and replaceScene?

查看:223
本文介绍了当我们应该使用pushScene和replaceScene?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I cocos2d,我使用pushScene和replaceScene移动到下一个场景。但是,我困惑,我们应该使用?

I cocos2d, I am using pushScene and replaceScene to move to next scene. But, I am confused which we should use?

当我在某些地方使用replaceScene时,应用程序崩溃,并显示

When I am using replaceScene in some places app is crashing and giving errors like

-[UITextView length]: unrecognized selector sent to instance 0x842a750  
 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITextView length]: unrecognized selector sent to instance 0x842a750'  

但是,在我的程序中,我不传递长度到UITextView。我的程序是这样的

在scene1我有UITextView,我用scene2替换这个场景。

But, in my program I am not passing length to UITextView. My program is in this way
In scene1 I have UITextView, and I am replacing this scene with scene2. Then

-(id)buttonPressed:(id)sender
{
    [description removeFromSuperview];  // It is the textView(description)
    CCScene *Scene = [CCScene node];
    CCLayer *Layer = [scene2 node];

    [Scene addChild:Layer];

    [[CCDirector sharedDirector] setAnimationInterval:1.0/60];
    [[CCDirector sharedDirector] replaceScene: Scene];
}  

但是,当我在replaceScene中使用pushScene时,它工作正常。请澄清一下我们应该使用哪种情况?

But, when I am using pushScene in presence of replaceScene it is working good. Please clarify me which one should use in which cases ?

谢谢

推荐答案

所有情况。 pushScene方法将前一个场景保存在内存中,这很可能是为什么它不会崩溃。关于那个场景的东西是不是很正确,当它deallocates后replaceScene,崩溃发生。它与cocos2d的替换场景系统没有任何关系。

You will want to use replaceScene in almost all cases. The pushScene method keeps the previous scene in memory, which is most likely why its not crashing. Something about that scene isn't quite right and when it deallocates after a replaceScene, the crash occurs. It has nothing to do with cocos2d's replace scene system.

你在Scene1中的UITextView可能太频繁了。如果将其创建为自动释放对象,请不要向其发送发布消息。

Your UITextView in scene1 is probably released too often. If its created as an autorelease object, don't send it the release message.

这篇关于当我们应该使用pushScene和replaceScene?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆