Tutorial: cocos2d Xcode Project: Configure Xcode for Cross-Project Referencing
Search my cocos2d for iPhone FAQs & Tutorials
Please note that the blog search in the upper right corner doesn’t search my FAQs and Tutorials.- Note: please do not share direct download links to PDF files, the download links expire after a couple minutes!
In March 2009 Clint Harris outlined how to setup cocos2d for iPhone using cross-project references, instead of copying the source code to every project you create. Since that article is completely outdated i decided to retrace the steps needed for version 0.99 of cocos2d engine and the current Xcode version 3.2. I've also condensed it to the necessary steps.
Apple's documentation also describes Xcode cross-project references in a short paragraph. I mention that in case you want to look that up and find that Clint's link does no longer work.
I use the cross-project solution instead of installing and using the cocos2d Xcode project templates because they, too, leave you in a situation where you'll find yourself unable to update the cocos2d engine code at a later time.
Note that the following settings need to be done only once but are required steps for the next lesson.
Shared Build Location
Open Xcode and from the Apple menu select Preferences. Switch to the "Building" tab and set the two radio buttons as in the screenshot. Choose a build folder where you want Xcode to place all build output. It should be an empty directory.
Define cocos2d Source Tree
Still in Preferences, click on the Source Trees tab. Click the + button to add a new setting and name it COCOS2D_SOURCE. As path enter the full path to the folder where you downloaded (pulled) the cocos2d-iphone source code. I'm afraid there's no "Choose..." button for this setting that lets you browse folders so you'll have to enter the path manually. Make sure the path is correct.
We'll refer to that COCOS2D_SOURCE variable a few times later on.
Comments (1)
170 Responses to “Tutorial: cocos2d Xcode Project: Configure Xcode for Cross-Project Referencing”
-
I get “cocos2d.h:No such file or directory” when trying to #import “cocos2d.h”
what am I missing?
-
ups, the path to the source code was wrong.
-
-
This tutorial is toooo long.
Is there a short version ? I spent two hours on this and as I expected nothing works.
For begininers its not going to work -
Great info! Thanks! However, the script is building the .ipa file before it does the codesign step. Have things changed in Xcode? How do I get the script to run after the codesign step?
-
I tried twice to follow your tutorial step by step using cocos2d 0.99.5-rc1, Xcode 3.2.5 and iOS 4.2.1, but I keep having problems when building and running on device.
The weird thing is I have no problem at all running the template on simulator!
To be more clear:
I’m trying to build and run following the final step of “Getting our Project Template to build minimal cocos2d code” section.
Running on simulator works perfectly, running on device (iphone4) crashes after splash screen with this message on console:
“Program received signal: “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Previous frame inner to this frame (gdb could not unwind past this frame)”
By stepping with debugger I found the app crashes on line 98 of AppDelegate.m:
“// make the View Controller a child of the main window
[window addSubview: viewController.view];”I see there are little differences from your (great) tutorial and Xcode/cocos2d new templates, mainly for the use of RootViewController, may this crash be related? (I already added RootViewController.* to my template)
Has anyone found a fix to this problem?
Please please please help me, this thing is driving me crazy =/
Thanks -
Hi Steffen
To upgrade a project created with your template from e.g. 0.99.5 rc1 to the final 0.99.5 I just need to copy over the cocos2d-IPhone folder?
I would assume yes but thought of asking since it does not clearly covered in the main points/links at the top of this tutorial
-
I receive a lot of EAGLView may not respond to …xxx warnings, and I believe these are the undeclared selectors you are mentioning in your comment. How can I fix it? Only with turning off the treat warning as error option or also by changing the code?
I didn’t understand where to implement the code from your comment on this tutorial.
-
BTW, the entire tutorial is really great!!
-
-
Hi
1st: GREAT job on this PDF. Realllly appreciated.I just did the first part up to Helloworld with the 99.5 version. (up to page 43 of pdf)
You might want to update a bit, the part where we get the AppDelegate from Helloworld sample : since in 99.5 Cocos changed the samples so that for exemple main.m does not exists main() is in the delegate.m file.
Continue the great work.
May 10, 2010 15:45
Yes, i keep getting reports of images not shown. I'm not sure what it is. I'll keep an eye on it.