이 아닌 GameScene 클래스가 있습니다. 싱글 톤 인스턴스입니다. 따라서 사용자가 새 레벨을 선택하고 "정적"/ "공유"데이터를 다른 싱글 톤 클래스 (예 : GameManager)에 보관할 때마다 할당하고 할당을 해제합니다.Cocos2d, iOS : 캐시에서 스프라이트를 제거하는 올바른 방법은 무엇입니까?
ARC입니다. 내 접근 방식이 메모리 관리 관점에서 올바른지 이해하고 싶습니다. 즉, 정리에서 "removeUnusedSpriteFrames"를 호출하는 것으로 충분합니까? 이것이 게임 아트에서 모든 스프라이트를 제거 할 것인가? CCSpriteBatchNode와 함께 뭔가를해야합니까?
-(void) loadGameArtFileForLevelOne //I do this in a switch but this is to simplify the reading
{
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"game-art-forLevelOne-hd.plist"];
CCSpriteBatchNode * sharedSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"game-art-forLevelOne-hd.png"];
}
//As dealloc is deprecated for ARC code, I prefer to remove unused sprites and texture on cleanup
-(void) cleanup
{
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
}
CCSpriteBatch 노드의 dealloc 메소드에서 CCLOG 호출을 추가했습니다. GameScene을로드 한 다음 메뉴로 돌아 가면 예상대로 "사용하지 않은 텍스처 제거"로그가 표시되지만 CCSpriteFrameCache의 dealloc 메소드 로그가 표시되지 않습니다. * !! 경고 : 아래 편집을 참조하십시오 - 내 실수! *
편집 : 죄송합니다, 나는이 난에 "무료"원하는대로 나를 약간 우려와 스프라이트와 관련된 모든 메모리를 제거 CCSpriteBatch
의 할당 해제의 방법의 모든 로그를 볼 수 없습니다 의미 수준.
이 내용을 이해하면이 비트를 "최적화"합니다 (예 : 레벨 1의 스프라이트 시트 - 예 : 세계 1 - 각 배경에 스프라이트 시트 1 개).
의견이 있으십니까?
dealloc 메소드는 더 이상 사용되지 않지만 계속 사용할 수 있습니다. dealloc에서 [super dealloc]을 호출하는 것은 더 이상 허용되지 않습니다. – LearnCocos2D