Rendel
Rendel

Reputation: 61

iPhone: Application crashes when I add a layer

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:

picture

Upvotes: 0

Views: 140

Answers (2)

Shailesh
Shailesh

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

aleroot
aleroot

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

Related Questions