2012-09-01 28 views
0

我的應用程序崩潰,當我嘗試在它與CCSprite添加一個圖層。
下面是一些代碼,我用:iPhone:應用程序崩潰時我加層

CCLayer *layerPause = [CCLayer node]; 
CCSprite *spriteBackgroundPause = [[CCSprite alloc] initWithFile:@"BackgroundMenu.jpg"]; 
[layerPause addChild:spriteBackgroundPause]; 
[self addChild:layerPause z:27]; 

下面是圖片也:

picture

回答

2

您必須保留layerPause變量,因爲它似乎是一個自動釋放的對象,嘗試了這種方式:

CCLayer *layerPause = [[CCLayer node] retain]; 
CCSprite *spriteBackgroundPause = [[CCSprite alloc] initWithFile:@"BackgroundMenu.jpg"]; 
[layerPause addChild:spriteBackgroundPause]; 
[self addChild:layerPause z:27]; 
+0

嘿感謝了很多。它現在有效。 – Rendel

0

爲什麼不這樣做簡單..?就像這樣:

CCLayer * layer = [CCLayer alloc]init]; 
[self addchild: layer]; 

CCSPrite * sprite = [CCSPrite spriteWithFile:@"ImageName.png"]; 
[layer addChild:sprite]; 
+0

我想,也但我得到了相同的結果:( 還是要謝謝你保持層,幫助我:。)) – Rendel