Search code examples
cocoa-touchcocos2d-iphoneuikitbuild-settings

Thought I successfully added Cocos2D to my Cocoa Touch project, but autocomplete shows no CC classes


Following several online tutorials, I managed to get Cocos2D added to my Cocoa Touch (UIKit) project. Problem is, I'm able to #import "cocos2d.h" at the top of any one of my files and my game compiles and runs fine, working just as it did before, but I don't have access to any of the cocos classes, like CCNode, CCLayer, etc.

To give you an idea of what the app does, currently, the main menu UITableView comes up, scrolls as it should, buttons that lead to various view controllers (facebook, twitter, new game creation, store, settings, etc.) all work fine. Back buttons in each view return the user to the main menu table view. This is pretty much all it does, as of now. The idea at this point would be to pass the baton to a Cocos2D scene--where the gameplay would be--when the user taps on one of the UITableViewCell's that represents a current match.

The process I used to add Cocos2D to my project was this:

  1. Drag and drop the cocos2d-ios.xcodeproj into my "supporting files" folder
  2. Under "Link Binary with Libraries" heading under "Build Settings" for my project, I added libcocos2d.a (which continues to show up red, even after "successfully" adding Cocos2D), libz.dylib, OpenGLES.framework, and QuartzCore.framework. They all read "required."
  3. Under "Build Settings" for my target, set "User Header Search Paths" to "/Users/Home/Downloads/cocos2d-iphone-master-v2/**" (recursive), which is where my Cocos2D library folder is.
  4. Under "Build Settings" for my target, set "Always Search User Paths" to YES.
  5. Did the same two steps identically for my project's "Build Settings"
  6. Went through and selected all the Cocos2D .h and .m files and set -fno-objc-arc compiler flags for all Cocos2D files, which enables the pre-ARC calls to retain, release, dealloc, etc. in the old Cocos2D files to play nice with all the post-ARC files in my project.

Also worth noting, perhaps, is that when I create a new file in my existing project "cmd + n", the only options available to me under Cocos2D templates is the CCNode class.

Am I missing something, here? Again, to be clear, I can import the cocos2d.h file and it looks as though everything will work fine. But, when I try to define anything that starts with a "CC", autocomplete shows nothing. Any help would be appreciated. Beating my head against the wall, here. TIA


Solution

  • The autocomplete issue is most likely because of the recursive search path. Xcode has problems indexing recursive header search paths (especially if you just drop in a .xcodeproj). Change it to an absolute path, add multiple paths if the source files are spread across multiple folders.

    With Xcode 4 you shouldn't drop in a xcodeproj to another project anymore. Use a workspace to combine multiple projects side-by-side in a single workspace. See Kobold2D for an example (or just use it if you continue to have problems, because these things are already solved in Kobold2D).