开发者

Releasing Cocos2d texture atlases

开发者 https://www.devze.com 2023-04-02 05:35 出处:网络
How does one release a texture atlas using cocos2d? I have the following code NSString *blue= = @\"Blue.plist\";

How does one release a texture atlas using cocos2d?

I have the following code

NSString *blue= = @"Blue.plist";
CCSpriteBatchNode *blueBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"Blue.png"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile开发者_JS百科:blue];
[self.parentScene addChild:blueBatchNode];

How do I release these 2 at a laster stage?


[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:@"Blue.plist"]


Most if not all CCNode derived objects are auto released. So long as you use convenience methods not alloc init.

e.g.

CCSprite *sprite = [CCSprite spriteWithFrameName:@"blahblah"];

Once your CCLayer removes the batchnode as a child, it should release that object, unless there are somehow some things linking to it, perhaps children that didn't get removed (but they should do).

Failing it being removed when that happens, you can also use purgecacheddata to clear out textures.

    [[CCDirector sharedDirector] purgeCachedData];

Purging cached data also removes cached spriteframes as mentioned in the question above.

0

精彩评论

暂无评论...
验证码 换一张
取 消