Tutorial: cocos2d Xcode Project: Configure Xcode for Cross-Project Referencing Comments Feed" href="http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-cocos2d-xcode-project-template/feed/"/>

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.
  • No images? Reload page, wait and try again.
  • PDF download broken? Reload page, try again.
    • 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.

Download Lesson PDF

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)

  1. Steffen Itterheim

    Yes, i keep getting reports of images not shown. I'm not sure what it is. I'll keep an eye on it.

Add Your Comment

13 Responses to “Tutorial: cocos2d Xcode Project: Configure Xcode for Cross-Project Referencing”

  1. Receptor says:

    Hi, I really liked this tutorial. It’s very well written!
    One question though. From the title I thought I would end up with an actual XCode template that I can find when I choose New Project. Did I misunderstand or miss something?

    Thanks!

    • GamingHorror says:

      No, apparently i was blissfully unaware of the actual Xcode ___TEMPLATE___ structure developers expect. It’s still a template in my eyes but i was rather thinking of using it together with source control. Meaning the project template is a base project that you can branch off of via source control software, then make changes to either the new or the base project and when you need it you can integrate the changes back.

      If you don’t use source control simply make a copy of the project in the same folder, then rename it. Other than that you have to use Xcode’s “Rename Project” functionality there’s no difference to an actual project template, nor does a real Xcode Template provide you with more or better features other than that you can select it from New Project and name it, instead of making a copy of the folder. So i don’t see the big gain of having a Project Template you can select from Xcode itself and if you use source control, it’s actually a hindrance.

      PS: one user just sent me a real __TEMPLATE__ … i’ll have a look at it and will post it here if it works.

  2. Magnus says:

    Hey Steffen

    I’m a Graphic Designer and Illustrator who has would like to get into and use Cocos2D to create a game. I have some knowledge of HTML and CSS, but that’s as far as my programming skills go. I have read about Objective C and downloaded Xcode and the iPhone SDK, however I feel there are some basics I still can’t find explained anywhere, such as class, object, how to debug. I have also tried several online tutorials, but keep hitting obstacles in the form of errors. I believe some of the reading I have done is simply outdated, while some of it is just too complicated.

    What do you think is the best way to learn to use Cocos2D completely from scratch, and do you know any resources that would be a good read for someone in my position? Any help would be appreciated.

    Cheers
    Magnus

    • GamingHorror says:

      Hi Magnus,

      since you have little programming experience you should try it with books. Granted, you can learn from the Web but as you experienced it, things can be outdated, or just plain wrong, and instead of a learning curve you’re facing a tour de force. I can recommend “Learn Objective-C on the Mac” from Apress, it’ll also help you understand the concepts of classes, properties and things like that. From there you can step up to “Beginning iPhone Development”, also from Apress.

      For a quickstart in Objective-C i can recommend this link: http://cocoadevcentral.com/d/learn_objectivec/

      I agree that for debugging there are little good tutorials and there are as many techniques as there are errors/bugs/crashes. Here it’s not so much about the tools and how they work but more about when to use which tool and how depending on the type of problem you’re having. Maybe i can shed some light on this, i made a note in my todo list.

      Btw, i can totally relate to your position because you’re not just facing to learn cocos2d as a game engine but also Xcode, Objective-C and general programming techniques. So it can be overwhelming, i was facing something similar even as an experienced programmer when i had to build a tool on my own, with half a dozen new technologies and new programming mehodologies. While it may be frustrating and painful, stick to it. You’ll learn a lot! I wouldn’t want to repeat the pain but more than that i wouldn’t want to miss what i’ve learned so painfully. And it always helps to partner up, even if it’s just on a forum. I believe one of the most effective ways to solve a problem is to try to ask someone for an answer - i’ve written many emails i’ve never sent because in the process i realized what i hadn’t tried yet.

  3. freeforce says:

    Broken img links on this tutorial.

    • GamingHorror says:

      Hmmm they work for me. But you’re the second person to report broken images. Could it be an adblocker? I took a look at the image names and they all have this in their name: “Upgrade_Target_for_iPad.png”. Harmless until you consider that the filename ends in “ad.png” and if your adblocker is overly aggressive i’m sure it’ll filter that.

  4. freeforce says:

    It’s been working fine until this morning, I was going thru your tutorial again since I did something wrong when I use the template. I keep getting errors when I build it, it says; Cocos2d.h : No such file or directory.

    I’m going over your tutorial over and over again to see if I missed any details, but I cant find anything. I’ve not been doing programing since C64 was hot, so it’s been a while….by the way sound like I’m a hundred y/old, I’m 32.

    Would be nice with a tutorial about how to go about when sketching out the idea, graphics design etc, all pre-work that goes into the project before you start programing.

  5. dfdf says:

    want to see images!

    • GamingHorror says:

      Can you try again please? There seem to be temporary broken images, i’m still trying to figure out what’s causing it. In the meantime, waiting a few minutes and refreshing the page seems to fix the images.

  6. favog says:

    Thanks for putting up the project. I’m getting close to finishing my first app, and was thrilled to see an easy way to update the cocos2d libraries, so I’ve moved everything over.

    The app builds, but I’m having one problem. I’m using the simpleAudioEngine and am having absolutely no luck linking to it. I’ve added the CocosDenshion dependency to the targets, am including SimpleAudioEngine.h like I always had, but still get
    Undefined symbols:
    “.objc_class_name_SimpleAudioEngine”, referenced from:
    literal-pointer@__OBJC@__cls_refs@SimpleAudioEngine in edgeMates_SpanishAppDelegate.o
    literal-pointer@__OBJC@__cls_refs@SimpleAudioEngine in tile.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Could you tell me what I’m missing?
    Thanks

    • GamingHorror says:

      You need to add CocosDenshion both as a Dependency and Linked Library. If you choose Get Info on a Target and select the General Tab, under Direct Dependencies it should list “CocosDenshion (from cocos2d-iphone.xcodeproj)” and below under Linked Libraries the file “libCocosDenshion.a” must also be listed. You probably forgot one of these two steps, probably the latter. To add libCocosDenshion find the file by selecting the cocos2d-iphone project in the Groups & Files and then drag & drop it onto a Target. Repeat for each Target. I hope this helps, let me know!

  7. favog says:

    That was exactly it! I read and re-read that section several times, but didn’t look deeply enough to find the .a file. Really looking forward to using your memdebug build. I knew I was going into optimization blind.

    thanks,
    bob

Leave a Reply