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 8293265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:45:52+00:00 2026-06-08T13:45:52+00:00

The coco2d game which is UIView is launched from viewcontroller as such coco2dgame=[[coco2d_view alloc]

  • 0

The coco2d game which is UIView is launched from viewcontroller as such

           coco2dgame=[[coco2d_view alloc] initWithFrame:CGRectMake(0,0,320,480)];
            [self.view addSubview:coco2dgame];

when it ends

         [coco2dgame.director end];
         [coco2dgame removeFromSuperview];
          coco2dgame=nil;

when I want to relaunch I call again

           coco2dgame=[[coco2d_view alloc] initWithFrame:CGRectMake(0,0,320,480)];
            [self.view addSubview:coco2dgame];

but I am getting errors

           OpenGL error 0x0502 in -[CCSprite draw] 532

            OpenGL error 0x0502 in -[CCSprite draw] 532
  • 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-06-08T13:45:53+00:00Added an answer on June 8, 2026 at 1:45 pm

    Your code setup seems to be a little whacky. You are loading cocos2d on a UIView, but retaining the director (a ViewController) on that view. Launching and ending the cocos2d engine within a ViewController structure can be a bit tricky, but this is what I use in my game:

    Step 1: Modify the standard code in AppDelegate.m from the template. You need to comment out all of the lines dealing with the _director ivar, and change the root view controller from _director to your ViewController. The game will now launch into that ViewController within the navController created in the cocos2d template code instead of the _director.

    Step 2: The ViewController that you’re launching cocos2d from needs to have a method that is called in -init that creates and, this is important, retains the CCGLView that the director uses as its view, like so:

    AppController *app = (AppController *)[[UIApplication sharedApplication] delegate];
    myGLView = [[CCGLView viewWithFrame:[app.window bounds]
                            pixelFormat:kEAGLColorFormatRGB565  //kEAGLColorFormatRGBA8
                            depthFormat:0   //GL_DEPTH_COMPONENT24_OES
                     preserveBackbuffer:NO
                             sharegroup:nil
                          multiSampling:NO
                        numberOfSamples:0] retain];
    

    Keeping the CCGLView around is important to preventing some OpenGL errors, as cocos2d seems to have an issue recreating it after it is destroyed. Like I said, this method is called only once, in the -init method of the ViewController you are launching cocos2d from.

    Step 3: Create a method in your ViewController to setup the director and push it onto the navigation controller’s stack, like so:

    AppController *app = (AppController *)[[UIApplication sharedApplication] delegate];
    
    CCDirectorIOS* director = (CCDirectorIOS *) [CCDirector sharedDirector];
    director.wantsFullScreenLayout = YES;
    [director setView:myGLView];
    // Display FSP and SPF
    [director setDisplayStats:NO];
    
    // set FPS at 60
    [director setAnimationInterval:1.0/60];
    
    // for rotation and other messages
    [director setDelegate:app];
    
    // 2D projection
    [director setProjection:kCCDirectorProjection2D];
    //  [director setProjection:kCCDirectorProjection3D];
    
    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if( ! [director enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");
    
    if (director.runningScene)
        [director replaceScene:[TwoPlayerBoard node]];
    else
        [director pushScene:[TwoPlayerBoard node]];
    
    [app.navController pushViewController:director animated:YES];
    

    Most of that code is actually copied from the commented out code in AppDelegate where the original director would have been setup. Notice, you set the director’s view to the CCGLView you create and retain in your ViewController’s -init. In this method, you have the newly created director push your startup scene.

    Step 4: Inside the game layer, whenever you want to return to your ViewController that the game (cocos2d) is launched from, implement this code:

    AppController *app = (AppController *)[[UIApplication sharedApplication] delegate];
    [app.navController popViewControllerAnimated:YES];
    [[CCDirectorIOS sharedDirector] end];
    

    That should allow you to move freely from a view controller, to the director in cocos2d (also a sub-class of UIViewController), and back without any issues. Hopefully that explains it in sufficient detail for you, let me know how it goes!

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

Sidebar

Related Questions

I have game application (cocos2d) in which, a ball is to be shooted from
I am developing cocos2d game, which supports multiple languages. I created a font file(.png
I have a text in my game which is written in cocos2d. The text
In my cocos2d game i have a some balls which must be destroyed, and
I am implementing game application.In which there is some mosquito(object).They moves randomly on the
In my game, which is using cocos2d, there is going to be many different
I'm building a cocos2d game which is supposed to be in portrait mode. I
I have a usual iOS Cocos2d game. I start with a MainMenuViewController, which then
I am planning to make treasure hunt game which will contain particles effect,animation, Pinch
I am trying to write an iPhone game using cocos2d and Box2D, which means

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.