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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:52:53+00:00 2026-05-15T15:52:53+00:00

I have an iPhone application that is mostly using standard controls. There is one

  • 0

I have an iPhone application that is mostly using standard controls. There is one view that is rendered in OpenGL (fancy graphs). In the interest of saving myself a lot of work, I looked around and found Cocos2d. It looks like it has exactly what I need (OpenGL ES, relatively simple to work with), but I’ve run into a problem.

I don’t know how to limit Cocos2d to exist in just a single view. Before, I implemented my OpenGL stuff in a view and used a simple ViewController to present it within a navigation controller. Here, Cocos2d seems to need to do a lot more, and I’m unsure how to stuff it into the same ViewController/View approach I did with raw OpenGL.

UPDATE: This is what I was doing. Flip to the next bold to see what I’m doing now.

#import <UIKit/UIKit.h>


@interface CocosController : UIViewController {
    UIWindow *window;
}

@property (nonatomic,retain) UIWindow *window;

@end

And my CocosController.m:

#import "CocosController.h"
#import "SomeScene.h"
#import "cocos2d.h"

@implementation CocosController

@synthesize window;

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
    // Initialization code
    CC_DIRECTOR_INIT();
    CCDirector *director = [CCDirector sharedDirector];

    //landscape
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
    [director setDisplayFPS:true];

    //turn on multi-touch
    EAGLView *cocosView = [director openGLView];
    [cocosView setMultipleTouchEnabled:true];

    self.view = cocosView;

    //default texture formats...
    [CCTexture2D  setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];

    [[CCDirector sharedDirector] runWithScene:[SomeScene scene]];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [[CCDirector sharedDirector] purgeCachedData];
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [[CCDirector sharedDirector] release];
    [window release];
    [super dealloc];
}


@end

And, finally, how I’m trying to present it (in a button click):

CocosController *cocosController = [[CocosController alloc] init];
[[self navigationController] pushViewController:cocosController animated:true];

This is the new approach, same results though.

ApplicationDidFinish portion of my AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeThreadMainLoop];

    CCDirector *director = [CCDirector sharedDirector];
    [director setDisplayFPS:YES];

    state = kStateEnd;

    // Add the navigation controller's view to the window and display.
    [window addSubview:navigationController.view];
    [window makeKeyAndVisible];

    return YES;
}

CocosController I’m using to present the view:

#import "CocosController.h"
#import "cocos2d.h"
#import "SomeScene.h"

@implementation CocosController

@synthesize mainView;

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
    EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0, 0, 250,350)];
    [mainView addSubview:glview];

    CCDirector *director = [CCDirector sharedDirector];
    [director setOpenGLView:glview];

    CCScene *scene = [CCScene node];
    id node = [SomeScene node];
    [scene addChild: node];

    [director runWithScene:scene];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

And this bit is from a button click in a details ViewController I have that is supposed to make this whole thing appear:

CocosController *cc = [[CocosController alloc]init];
cc.mainView = self.view;
[[self navigationController] pushViewController:cc animated:false];
  • 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-15T15:52:53+00:00Added an answer on May 15, 2026 at 3:52 pm
    float row = (a % itemsPerRow) * texStepX;
    

    The above line of code was where the app was crashing every time I tried another way to get the view running. I finally just tried to look it up, thinking I wouldn’t find anything. Turns out, cocos2d makes an assumption that an image, fps_images.png, is assumed to be in the project. If it’s not, this particular bit of cocos2d explodes with an arithmetic exception.

    Took two seconds to fix by just finding fps_images.png in the cocos2d directory and adding it to the Resources folder of my project.

    sigh

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

Sidebar

Ask A Question

Stats

  • Questions 436k
  • Answers 436k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The terms "composition" and "aggregation" mean more or less the… May 15, 2026 at 3:54 pm
  • Editorial Team
    Editorial Team added an answer You could try CKEditor http://ckeditor.com/blog/CKEditor_for_jQuery (formerly FCKeditor) May 15, 2026 at 3:54 pm
  • Editorial Team
    Editorial Team added an answer You can do this with global.asax If this is a… May 15, 2026 at 3:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.