0

シーンの終了後にスプライトシートを削除する際に問題が発生しています..

基本的に、初期化で未使用のテクスチャを削除することにより、レイの指示に従います

[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
[[CCDirector sharedDirector] purgeCachedData];

そしてdeallocで私は持っています

CCTexture2D * texture = spriteNode.textureAtlas.texture;
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromTexture:texture];
[[CCTextureCache sharedTextureCache] removeTexture:texture];

参照

シーンへの遷移が現在のシーンでない場合、これはうまく機能します。しかし、現在のシーンを「再開」しようとすると、クラッシュします。

[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:2.0 scene:[currentScene scene] withColor:ccBLACK]];

問題は、現在のシーンを「新しい」現在のシーンに置き換えるときに、現在のシーンの割り当てが解除される前に「新しい」現在のシーンの初期化が呼び出されることです。したがって、「新しい」現在のシーンのスプライトシートは、作成直後に割り当てが解除されました。

この場合、どうすればスプライトシートを適切に削除できますか? または、現在のシーンを再開する私のアプローチは間違っていますか?

更新: アドバイスに従って読み込みシーンを追加しようとしましたが、機能しませんでした.. これが私の読み込みシーンです

+(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]];
} 

これにより、この場合は GameTwoLayer のスプラッシュが表示され、次に黒い画面が表示されます..何が間違っていますか?

4

1 に答える 1