Reputation: 61
My applications crashes when I try to add a layer in it with CCSprite
.
Here is some code I use:
CCLayer *layerPause = [CCLayer node];
CCSprite *spriteBackgroundPause = [[CCSprite alloc] initWithFile:@"BackgroundMenu.jpg"];
[layerPause addChild:spriteBackgroundPause];
[self addChild:layerPause z:27];
Here is picture also:
Upvotes: 0
Views: 140
Reputation: 3118
Why not do it simple .. ? Like this:
CCLayer * layer = [CCLayer alloc]init];
[self addchild: layer];
CCSPrite * sprite = [CCSPrite spriteWithFile:@"ImageName.png"];
[layer addChild:sprite];
Upvotes: 0
Reputation: 72636
You have to retain the layerPause
variable because it seems an autoreleased object, try in this way :
CCLayer *layerPause = [[CCLayer node] retain];
CCSprite *spriteBackgroundPause = [[CCSprite alloc] initWithFile:@"BackgroundMenu.jpg"];
[layerPause addChild:spriteBackgroundPause];
[self addChild:layerPause z:27];
Upvotes: 2