2
votes

I am using cocos2D game engine. And after few replays game scene starts blinking and sprites do not move at all. But the position of sprites moves as the player gets out. Every function gets called. But nothing appears. I have checked memory consumption through instruments. The memory consumption is fine. Any help is appreciated. Thanks in advance.

This is the code i use when i end the game.

[[CCDirector sharedDirector].openGLView removeFromSuperview];
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] end];

This is the code i use when i load the game scene again.

if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
    [CCDirector setDirectorType:kCCDirectorTypeDefault];

CCDirector *director = [CCDirector sharedDirector];

viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;

EAGLView *glView = [[EAGLView alloc] initWithFrame:[window bounds]];

[director setOpenGLView:glView];

if( ! [director enableRetinaDisplay:YES] )
    CCLOG(@"Retina Display Not supported");

[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];

[viewController setView:glView];
[window addSubview: viewController.view];
[window makeKeyAndVisible];

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];


[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer node]];
1
what do want to do?Clearly explain it.user1387047
I am using sprites and moving those sprites by changing their positions. Detecting pixelPerfect collisions of the sprites. If collision detected, ending the game scene. And then on replay i am starting new game scene again. This is happening in my game. For few replays the game goes well. But after some time when i replay the game, the game scene starts flickering. And sprites does not seems moving. But the game gets over, the collision is detected but nothing is visible. Just the screen starts flickering. This is my problem.NiKKi
strange behavior. post your restart code, pleaseMorion
@Morion - I have updated the question. PLease have a look.NiKKi
why just not [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]]; ?Morion

1 Answers

2
votes

I keep repeating my own advice, so I put it in quotes:

If you're using cocos2d in a Cocoa touch app, do not remove and recreate the OpenGL view all the time. Create it once, and keep it around. Also don't shut down cocos2d entirely. Only call stopAnimation and startAnimation. If you're very low on memory, replace the current cocos2d scene with an empty scene before stopping cocos2d and going back to the Cocoa touch part of your app.

Developers not following this advice keep running into all kinds of issues. Probably because cocos2d hasn't been well tested with repeated shutdown and restart cycles under various conditions.