Note that there are some explanatory texts on larger screens.

plurals
  1. POremoving texture
    primarykey
    data
    text
    <p>I am having some problem with removing my spritesheets after my scene exit..</p> <p>I basically follow Ray's instructions by removing unused textures in init</p> <pre><code>[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames]; [[CCTextureCache sharedTextureCache] removeUnusedTextures]; [[CCDirector sharedDirector] purgeCachedData]; </code></pre> <p>and in dealloc I have</p> <pre><code>CCTexture2D * texture = spriteNode.textureAtlas.texture; [[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromTexture:texture]; [[CCTextureCache sharedTextureCache] removeTexture:texture]; </code></pre> <p><a href="http://www.raywenderlich.com/forums/viewtopic.php?t=8&amp;p=4378#p2287" rel="nofollow">Reference</a></p> <p>This works fine if the transition to scene is not the current scene. But when I tried to "restart" the current scene it crashes.</p> <pre><code>[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:2.0 scene:[currentScene scene] withColor:ccBLACK]]; </code></pre> <p>Seems like the problem is that when replacing the current scene by the "new" current scene.. the "new" current scene init is called before the current scene is deallocated. Hence my "new" current scene spritesheet got deallocated right after it's being created.</p> <p>How can I properly remove the spritesheets in this case? Or is my approach to restart the current scene incorrect?</p> <p>Update: I was trying to add a loading scene as advised but couldn't make it work.. here's my loading scene</p> <pre><code>+(CCScene *) scene { // 'scene' is an autorelease object. CCScene *scene = [CCScene node]; // 'layer' is an autorelease object. LoadingLayer * layer = [[[LoadingLayer alloc]init]autorelease]; // add layer as a child to scene [scene addChild: layer]; // return the scene return scene; } -(id) init{ if(self = [super init]){ winSize = [CCDirector sharedDirector].winSize; CCLabelTTF * loadingLabel = [CCLabelTTF labelWithString:@"Loading..." fontName:@"Marker Felt" fontSize:30]; } loadingLabel.position = ccp(winSize.width/2, winSize.height/2); [loadingLayer addChild:loadingLabel]; [self scheduleUpdate]; } return self; } -(void) update:(ccTime)dt{ [self unscheduleUpdate]; NSString * bgPlist = @"backgroundsIPAD.plist";; NSString * hudPlist = @"hudSpritesIPAD.plist" NSString * gameOnePlist = @"gameOneSpritesIPAD.plist"; // load background [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:bgPlist]; // load hud [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:hudPlist]; // load sprites [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:gameOnePlist]; [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:2.0 scene:[GameTwoLayer scene] withColor:ccBLACK]]; } </code></pre> <p>This will give me a splash of the GameTwoLayer in this case, then a black screen.. What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload