0

我正在崩潰的應用程序在控制檯中發出上述警告。警告:收到內存警告。 Level = 1&2

有兩個精靈。

Train=[CCSprite spriteWithFile:@"train.png"]; 
    [self addChild:train z:0 tag:1]; 

    AlphaImage=[CCSprite node]; 
    AlphaImage.position=ccp(245,155); 
    [Train addChild:AlphaImage z:1 tag:2]; 

在其他方法我使用動畫初始化AlphaImage。

CCSpriteFrameCache *frameCache1 =[CCSpriteFrameCache sharedSpriteFrameCache]; 
[frameCache1 addSpriteFramesWithFile:plist1];         
CCSpriteBatchNode *danceSheet1 = [CCSpriteBatchNode batchNodeWithFile:png1];  
[self addChild:danceSheet1];         

NSMutableArray *animFrames1 = [NSMutableArray arrayWithCapacity:frame[x]];  
for(int i = 1; i < frame[x]+1; i++) { 
    NSString *namef1=[NSString stringWithFormat:@"%@%i.png",alpha1,i];    
    CCSpriteFrame *frame1 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:namef1]; 


    [animFrames1 addObject:frame1]; 
} 

CCAnimation *anim1 = [CCAnimation animationWithFrames:animFrames1 delay:0.3f]; 
CCAnimate *animN1 = [CCAnimate actionWithAnimation:anim1];      
CCRepeatForever *repeat1 = [CCRepeatForever actionWithAction:animN1];     
[AlphaImage runAction:repeat1];  

我已經使用zwoptex創建plist和紋理圖集。
隨着火車駛過並返回動畫更改的plist和Texture Atlas。但是在4或5次應用程序崩潰之後。我也deallcated所有幀和紋理之前新的動畫來AlphaImage.i都用這個:

[CCSpriteFrameCache purgeSharedSpriteFrameCache]; 
[CCTextureCache purgeSharedTextureCache]; 

我使用的application.I經歷了許多文件了高清圖像,他們建議這些:

[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames]; 
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames]; 

但在控制檯中,它沒有顯示任何有關使用這些行刪除幀的信息。 有什麼我做錯了嗎?

回答

1

你在哪裏運行[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];這條語句使用NSObject的performSelectorInBackground方法運行它後臺線程。

+0

在我的AllReset方法中,我有動畫代碼(上面的代碼),在此之前我調用了包含此代碼的removeUnused方法。 – user392406 2011-04-14 08:01:11

+0

將此頁面引用爲performSelectorInBackground - http://blog.datispars.com/tasks-in-background-thread-cocoa-performselectorinbackground/ – nishantcm 2011-04-14 08:31:45

+0

performSelectorInBackground對選擇器不響應它將進入循環。 – user392406 2011-04-15 06:26:10

0

嘗試在動畫結束後釋放數組。

//這可能是原因。

[animFrames1 release]; 
animFrames1 = nil;