首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何释放CCLayer

如何释放CCLayer
EN

Stack Overflow用户
提问于 2011-10-04 08:37:01
回答 1查看 692关注 0票数 0

我正在使用cocos2d为iphone制作一个box2d应用程序。我正在尝试将我的CCLayer从HelloWorldLayer切换到HomeScene,但我收到错误消息"Thread 1: Program received signal:“EXC_BAD_ACCESS”。“当我试图在我的HelloWorldLayer的dealloc方法中调用超级dealloc时,它给了我这个错误。请帮帮忙。这是我的.h和.mm

代码语言:javascript
复制
@interface HelloWorldLayer : CCLayer
{
    b2World *world;
    Cannon *cannon1;
    Cannon *cannon2;
    Cannonball *cannonball1;
    Cannonball *cannonball2;
    float theMass;
    float theMass2;
    CCSprite *sunBack;
    b2Vec2 cannon1Pos;
    b2Vec2 cannon2Pos;
    CCMenuItemSprite *pauseBut;
    CCMenuItemSprite *playBut;
    CCMenu *pauseMenu;
}
@property(nonatomic)b2Vec2 cannon1Pos;
@property(nonatomic)b2Vec2 cannon2Pos;

@property(nonatomic, retain)CCSprite *sunBack;
@property(nonatomic, retain)Cannon *cannon1;
@property(nonatomic, retain)Cannon *cannon2;
@property(nonatomic, retain)Cannonball *cannonball1;
@property(nonatomic, retain)Cannonball *cannonball2;
@property(nonatomic, retain)CCMenu *pauseMenu;

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
+(HelloWorldLayer *) sharedLayer;
-(void)createMonkeys;
-(void)restartGame;
-(void)playGame;
-(void)pauseGame;
-(CCSpriteBatchNode*)getSpriteBatch;
-(void)goToHome;

@end

这是我解除分配的.mm

代码语言:javascript
复制
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
    // in case you have something to dealloc, do it in this method
    delete world;
    world = NULL;
    [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
    [cannon1 removeFromParentAndCleanup:YES];
    [cannon2 removeFromParentAndCleanup:YES];
    [cannonball1 removeFromParentAndCleanup:YES];
    [cannonball2 removeFromParentAndCleanup:YES];

    // don't forget to call "super dealloc"
    [super dealloc];
}
EN

回答 1

Stack Overflow用户

发布于 2011-10-14 21:05:14

你可以试试这个,而不是你用过的dealloc

代码语言:javascript
复制
-(void) dealloc
{
delete world;
world = NULL;
cannon1 = NULL;
cannon2 = NULL;
cannonball1 = NULL;
cannonball2 = NULL;
[super dealloc];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7642183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档