cocos2d场景保留问题
我的应用程序中有一个场景,只有两个标签和一个菜单项。当我使用 replaceScene
方法加载此场景时,它会停留 3-4 秒,然后消失或释放。我想保留它直到按下取消按钮。我该怎么做呢?代码是:
@implementation MyLayer
+ (id)myScene {
CCScene *aScene = [CCScene node];
MYLayer *myLayer = [MyLayer node];
[aScene addChild:myLayer];
return aScene;
}
- (id) init {
if (self = [super init]) {
//labels and menu here
}
return self;
}
我从另一个场景调用它,如下所示:
[[CCDirector sharedDirector] replaceScene: [MyLayer myScene]];
There is a scene in my application which has only two labels and a menu item. When I load this scene using replaceScene
method it stays for 3-4 seconds and then gets disappeared or released. I want to keep it until cancel button is pressed. How can I do it? code is:
@implementation MyLayer
+ (id)myScene {
CCScene *aScene = [CCScene node];
MYLayer *myLayer = [MyLayer node];
[aScene addChild:myLayer];
return aScene;
}
- (id) init {
if (self = [super init]) {
//labels and menu here
}
return self;
}
And I am calling it from another scene like this:
[[CCDirector sharedDirector] replaceScene: [MyLayer myScene]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许问题在于这是你的第一个场景。那么你应该使用
CCDirector
的runWithScene
方法。Maybe the problem is that it's your first scene. Then you should use
runWithScene
method ofCCDirector
.您是否尝试用“空”初始化函数替换该场景以查看它是否仍会自行释放?这可能是因为您放入内存中的纹理量
我之前确实遇到过类似的问题,因为新场景中使用的图像太大并且被我的应用程序委托自动清除,因此有时会返回一个空场景
did you try replacing that scene with a "empty" init function to see if it still releases itself? It might be because of the amount of textures you are putting into memory
I did have sort of similar problems before because the images used in the new scene is too big and got auto purged by my app delegate, thus returning me an empty scene sometimes