Daniel Klöck
Daniel Klöck

Reputation: 21157

Install cocos2D-iPhone manually

How can I install cocos2D-iPhone manually? I want to include the cocos2D framework into an existing project. Thus, I will not be able to use a cocos2D project template.

Tutorials or web sites would be appreciated (couldn't find any)

Upvotes: 1

Views: 977

Answers (2)

Daniel Klöck
Daniel Klöck

Reputation: 21157

I have found a tutorial at this site

Upvotes: 0

Sam Ritchie
Sam Ritchie

Reputation: 11038

I would create a new project using the template, and compare it to your own project. For a list of files to compare, and a rough procedure:

  1. Copy all cocos2d files from the template over to your project
  2. Check Info.plist, and make any necessary changes
  3. Modify main.m in your target to specify your AppDelegate class. For a project called Untitled, you'd use

    int retVal = UIApplicationMain(argc, argv, nil, @"UntitledAppDelegate");
    
  4. Add a target that builds the cocos2d files. This will be a "Static Library" target. use "Get Info" on the template version to figure out exactly what's going on inside.

  5. Link required frameworks to your target: CoreGraphics, OpenGLES, QuartzCore, OpenAL, AudioToolbox, libz.dylib, AVFoundation. I think this is all
  6. Use "Get Info" on the template target and your target, and make sure you've added the cocos2d library to "Linked Libraries". Also, add "cocos2d libraries" as a linked target.
  7. Compare AppDelegate files, and check how the project is instantiated. The main difference is that you won't be using a Window.xib file to boot up the project, and will have to manually instantiate the cocos2d stuff. The best way to see the proper startup procedure is to take a look at the template code.

That said, I actually DO use a UINavigationController and a UIViewController with a nib file for my initial view. To do this, instantiate the navController like usual, and use this sort of code to attach it to cocos2d:

[[[[CCDirector sharedDirector] openGLView] window] addSubview:navController.view];

That should be everything you need to do for a basic conversion.

If you want access to the project internals, you might use the method of shared libraries, which will allow you to build a new cocos2d library every time you build your app. The link has a great tutorial on this.

Upvotes: 4

Related Questions