Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:15:11+00:00 2026-05-23T17:15:11+00:00

How do I restart cocos2d scene and clean memory after the previous one? [director

  • 0

How do I restart cocos2d scene and clean memory after the previous one?

[director replaceScene:s] is displaying pink screen. Can’t get it to work.

The work-around I made is below, however after closing scene this way app runs very slow and slowly reacts to touch. MainViewController.m:

- (IBAction)startScene { 

[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];

if ([director runningScene]) {
    [director end];
    works = NO;
}
if (!works) {
    EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0,0, 768, 1024)]; 
    [self.view addSubview:glview];
    [director setOpenGLView:glview];
    CCLayer *layer = [PlayLayer node];
    CCScene *s = [CCScene node];
    [s addChild: layer];
    [director runWithScene:s];
}

}

Inside PlayLayer.m I go back from scene to view using:

CCDirector *d = [CCDirector sharedDirector];
EAGLView *v = [d openGLView];
[v removeFromSuperview];

Application is displaying images (1280x960x32, imageview inside scrollview) and when user presses the button he can start cocos2d scene. User can then leave from scene back to view (.xib) and continue browsing through images till he finds a new one to start scene with.

I believe this is not a good way to leave scene but everything else I tried is causing app to crash or I keep getting this pink screen 2nd time I start scene. How do I restart it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:15:11+00:00Added an answer on May 23, 2026 at 5:15 pm

    Ok, found a solution that closes the scene from inside and works well.

    While starting scene I add the notification observer in my viewcontroller:

    (...)
    [director runWithScene:s];
    [[NSNotificationCenter defaultCenter] addObserver:self 
          selector:@selector(mySceneEnd:) name:@"scene_ended" object:nil];
    

    That is connected to:

    - (void) mySceneEnd:(NSNotification *)notif {   
        if ([director runningScene])
            [director end];
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    

    Then in the scene ending method I’m sending the notification to my viewcontroller:

    EAGLView *v = [[CCDirector sharedDirector] openGLView];
    [v removeFromSuperview];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"scene_ended" 
         object:nil userInfo:nil];
    

    Works really nice, app runs fast after closing scene, but it’s an old question/answer and there is surely a better way to do it now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After a server restart I sometimes get random CompilationException errors like this: CompilationException: CS0006:
I have to restart a scene created in cocos2d using a defined UIViewController. How
How can I automatically restart my service and broadcast receiver after the application gets
My question in the previous post was- I have a cocos2d game, and after
How can I restart(recycle) IIS Application Pool from C# (.net 2)? Appreciate if you
I need to restart the program that im working on after an update has
How can I restart gdm or the xserver without logging out? Sometimes, there is
How can I restart An Activity on click? For exemple: I have got in
How can I restart IIS 6 's defaultAppPool when I click a button of
How can I restart a windows service programmatically in .NET? Also, I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.