Home > iPhone Development > How to Install Cocos2d 0.8 Project Template

How to Install Cocos2d 0.8 Project Template

Step 1: Download Cocos2d 0.8 Beta project template from here. This template works well for 0.8 beta, rc, and final version.

Step 2: Unzip the downloaded file in Step 1. Move the the folder to project templates folder. On my desktop, this folder’s location is /Developer/Platforms/iphoneos.platform/developer/library/xcode/project templates/application.

Step 3: Download Cocos2d Library from here. Untar the file, then move the folder to /Developer/Library.

Step 4: Under xcode – Preferences – Source Trees, add a source record. You can set the setting name with COCOS2D_SRC. The path is the location of Cocos2d Library, which is /Developer/Library/cocos2d-iphone-0.8/

Step 5: Now, you can create a Cocos2d project in xcode. The Dependency and Linked Library of cocos2d and Chipmunk have been added to the project by default.

Step 6: If you want to use other libraries (e.g., Box2d, etc) integrated in cocos2d, please follow the steps below.

Step 7: Add Direct Dependency. After a new project is created, right click the target and select Get Info. Under General, click the ‘+’ button of Direct Dependencies. You will see a list of target dependencies, just add the dependency you want (e.g., box2d). This step can guarantee the static library always exists (if not, the compiler will build one).

Step 8: Build the project. The dependency you added in Step 7 was built up in this step.

Step 9: Add the Linked Static Library to the project. built up in Step 8. Right click the target and select Get Info again. Under General, click the ‘+’ button of Linked Libraries. In the popped-up library list, you can’t  find the library built up in Step 8. You need to click “Add Other” button. Then you need to find the library yourself. The library just built up is under the folder /Developer/Library/cocos2d-iphone-0.8/build/Debug-iphonesimulator. Select the library you just built up (e.g., libbox2d.a). Now, the library has been added to the project. Click cocos2d-iphone.xcodeproj on the left side, find the target (i.e., Static Library) you want to add from the file list on the right hand side. Just simply tick the target (e.g., libbox2d.a) as shown below:

All done!

———————–

Update: In the future, if a newer version of Cocos2d is released, what you need to do is just to replace the old Cocos2d library with the new one. You don’t need to update the template. It’s very easy, isn’t it?

Categories: iPhone Development
  1. July 28th, 2009 at 03:22 | #1

    Thanks a million. This is very useful. Just tried it with 0.8 and it works like a charm.

  2. Crazy Dev
    July 29th, 2009 at 04:47 | #2

    Hi,

    Thanks for this template.

    Before, i have created template for lower version and i removed this folder from /Developer/Platforms/iphoneos.platform/developer/library/xcode/project templates/application even though i am getting this template.

    I followed your way to create template for version 8 but i am getting old one and i am not able to get new template.

    Where i am wrong?.

    Thanks,

  3. admin
    July 29th, 2009 at 05:10 | #3

    to Crazy Dev,

    This post is actually presenting how to use the template mentioned in Step one. The template you downloaded in step one works well for all 0.8 versions, even though the downloading page said it is Cocos2d 0.8 Beta project template.

    If you only use Cocos2d and Chipmunk, you can ignore the step 6 to 9 because the dependency and linked library of Cocos2d and chipmunk have been set by default in the template you downloaded in Step 1. This is reasonable because Cocos2d and Chipmunk are mostly used. You only need to add other libraries when necessary. This can save a lot of compiling time.

    The step 6 to 9 is telling you how to add other libraries to a new project which is created with the template you have downloaded in Step 1.

  4. Gaurav
    August 4th, 2009 at 00:29 | #4

    hey
    first of all thanx for template

    i hav done all these steps but after build it i get the following error:

    Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0 failed with exit code 1

    what should i do..

    thanx in advance

  5. admin
    August 4th, 2009 at 01:08 | #5

    Hi Gaurav,

    The information you provided is too limited, but I think you haven’t
    added static libraries properly. Could you please provide more information
    or send me the project files, I can have a look.
    My email: jiangli001 [AT] gmail.com

  6. Gaurav
    August 4th, 2009 at 01:55 | #6

    Hey I am very thankful for ur reply

    hv just mailed u my project files..

    Thanks again

  7. August 6th, 2009 at 02:00 | #7

    I’ve done all the steps up to 5 but when I try to build it says that it cant find cocos2d.h

    I have cocos2d-iphone.xcodeproj in my project and it has the library libcocos2d.a
    Cocos2d.h is in that library correct?

    What am I doing wrong?

  8. admin
    August 6th, 2009 at 02:55 | #8

    @Markos

    Hi, i think there is a problem with the “user header search paths”. Please double click your project
    name on the sidebar to open project setting dialog. You should check if the User Header Search Paths include your Cocos2d library path.

  9. August 6th, 2009 at 05:06 | #9

    The path is fine I think. It points to $(COCOS2D_SRC) which is set as “/Developer/Library/cocos2d-iphone-0.8/” in the source trees of the preferences of xcode. So the path says “/Developer/Library/cocos2d-iphone-0.8//**”.

    Is there anything i am doing wrong?

  10. admin
    August 6th, 2009 at 05:23 | #10

    @Markos
    Yes, that’s correct if you put your library’s folder is /Developer/Library/cocos2d-iphone-0.8/. It’s a little strange. I tried it again, and it works fine on my desktop. You can send me your code if you want, I will have a look tomorrow. My email: jiangli001 [AT] gmail.com

  11. August 6th, 2009 at 22:22 | #11

    I had trouble as well Markos.

    Renaming the directory from “/Developer/Library/cocos2d-iphone-0.8″ to “/Developer/Library/cocos2d” fixed that problem using the 0.8 final.

    I’ve got a problem now that libbox2d.a isn’t compiling though, and the compiler is saying -lbox2d is missing… :(

    I definitely have box2d under the cocos2d, and it compiles but libbox2d.a is in the red… :(

  12. NigelH
    August 13th, 2009 at 10:38 | #12

    Hi

    I’m having the same problem – i think.

    ive done exactly what’s asked above and I get 91 errors when linking.

    cant find cocos2d.h libcocos2d libraries.a is red

  13. NigelH
    August 13th, 2009 at 10:47 | #13

    also cocos2d sources folder in project has all its files as red

  14. NigelH
    August 13th, 2009 at 16:16 | #14

    No worries – i downloaded the beta v0.8.1 and rand the template script. all is fine now

  15. doctorhsly
    August 17th, 2009 at 02:36 | #15

    Thank you very much for your aticle!!!:)

  16. RanReloaded
    February 7th, 2010 at 10:26 | #16

    It just won’t work…
    I did everything as written ere, and get 104 errors. The sources for Cocos2D aren’t being found (Files show in red). If I manually import them (“Add Existing Files”) I get 78 errors of the kind:

    “…gcc-4.2 failed with exit code 1″

    Libraries, Frameworks, User Defined Headers… Why does it have to be such a pain in the a**?

    I was happy with the bundled v0.7 until I wanted to add Denshion…

    *I’m using 10.6 with the latest SDK (3.1.3, Xcode 3.2.1).
    *I used the library version from step 3 in step 1 as well, because github was offline…

  17. RanReloaded
    February 7th, 2010 at 10:45 | #17

    Now I got github working but still… I’ll try 0.8.1 as NigelH said above…

  18. RanReloaded
    February 7th, 2010 at 10:54 | #18

    So in the end I run the install_template.sh bundled in 0.8.2 and it worked.

    I had to cd / in the console though, I tried double clicking the .sh file before and it wouldn’t work…

  19. Kamol
    July 27th, 2010 at 00:06 | #19

    I’ve been trying to install cocos2d with xcode but I coudn’t. Today it really helped me, at last I’ve successfully installed. Thank you very much.

  20. July 27th, 2010 at 01:49 | #20

    @Kamol
    Hi Kamol,
    Have you tried the installation script in the latest version of cocos2d iPhone?
    I think that would be easier.
    http://www.cocos2d-iphone.org/wiki/doku.php/resources:templates

  1. No trackbacks yet.