views:

27

answers:

1

I am writing a game in cocos2d. I am using a function restartDirector in AppDelegate class. -(void)restartDirector{

[[CCDirector sharedDirector] end];

[[CCDirector  sharedDirector] release];

if( ! [CCDirector setDirectorType:CCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:CCDirectorTypeDefault];

[[CCDirector sharedDirector] setPixelFormat:kPixelFormatRGBA8888];
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];

[[CCDirector sharedDirector] setAnimationInterval:1.0/60];
[[CCDirector sharedDirector] setDisplayFPS:YES];
[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];

[[CCDirector sharedDirector] attachInView:window];

}

This function I called in one of the game Scene .

-(void)PracticeMethod:(id)sender
{
[MY_DELEGATE restartDirector];

CCScene *endPageScene = [CCScene node];
CCLayer *endPageLayer = [DummyScene node];

[endPageScene addChild:endPageLayer];

[[CCDirector sharedDirector] runWithScene:endPageScene]; 

//  [[CCDirector sharedDirector] replaceScene:endPageScene];
}

When used the replaceScene, there is no problem in game but the memory of abject allocation is high(I checked in leaks tool). So I used runWithScene. But , while using these when the scene DummyScene is loaded the sprites, labels in it are displayed by white boxes. I cannot see the sprites and labels. If I am using replaceScene everything thing is working fine but the memory allocation is high. this is my problem.

alt text

Thank you.

A: 

You should only ever use runWithScene for the very first scene that is displayed. This is usually done in the AppDelegate. All further scene changes must be done using replaceScene.

Keep in mind that when you do a replaceScene, both scenes will be in memory at the same time. Unless you use an intermittent "loading scene" you'll see a spike in memory usage.

In addition, check that the dealloc method of your scenes get called. Set a breakpoint there or at the very least add a CCLOG statement. If the dealloc method is not called after the scene was replaced (and any transition has ended), then you're leaking the scene and you need to find the cause in the scene that you were leaving.

GamingHorror