9

I already have a project that is 90% done and I want to add Cocos2D ONLY to it. I do not need Box2D or Chipmunk. How would I do this? What files do I add? I really need this done, so in the end ill offer a bounty if needed.

Thanks!

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191

3 Answers3

16

To start the easier way to add Cocos2d into your project is to follow these lines:

  1. Import the Cocos2d files into your project like the picture below: Copy the Cocos2d file into the project

  2. Then import the "FontLabel" folder which is located into the "external" folder (Into the Cocos2d library) like the previous step.

  3. After, you have to link the OpenGLES and QuartzCore frameworks with your project: enter image description here

  4. Next in the "Project navigator", select your target and open the “Build Settings” tab.

  5. Add the -lz flag into the "Other Linker Flags": enter image description here

That's all! No it should compile properly.

However I don't if you want to use Cocos2d with the UIKit framework or if you want use it as the main entry. If you want more details about these steps you can check the Ray Wenderlich blog's post.

I hope it'll help you.

Yannick Loriot
  • 7,107
  • 2
  • 33
  • 56
  • Wow! I was always so close to importing it just like this but people never mentioned I had to import OpenGLES or do the -lz flags. It was imported perfectly! I want to use Cocos2D in my UIKit app so where should I go from here to use it for one UIView in my project? – SimplyKiwi Sep 18 '11 at 17:47
  • 2
    Take a look to this tutorial http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit (in the "Connecting the Cocos2D View" section). It is very well explained. – Yannick Loriot Sep 19 '11 at 08:13
  • One question. In the tutorial it talks about HelloWorldLayer. It seems like that is its own class or something. In my case I don't have a specific class like that. Whats the point of the HelloWorldLayer? Do I need to make a class like that, and if so how would I if I only need Cocos2D in one of my UIViews? – SimplyKiwi Sep 20 '11 at 03:10
  • His "HelloWorldLayer" is just a CCLayer. When you want work with Cocos2d you have to manage scenes which manage layers. In this tutorial the "setupCocos2D" method just initializes Cocos2d with a layer by default which is the HelloWorldLayer. I think the best is to download the sample project and see how it works and play with the code to learn the mechanism which is hidden behind. – Yannick Loriot Sep 20 '11 at 07:50
  • Thanks for the info! Anyway so I see how it works now but I am still a little confused on what I exactly need for my case. So I do need a CCLayer for Cocos2D in just one of my views? If so, what code would be inside it, how do I know what goes in there? Thanks for all your help!!! =D – SimplyKiwi Sep 22 '11 at 04:09
  • One issue, I am trying to import Box2D into my project, I get 4 errors like b2Collision not found, but the Box2D was just downloaded so that can't be an issue. Is there something different that I need for Box2D that I got from the Cocos2D download? – SimplyKiwi Oct 10 '11 at 19:42
  • This doesnt seem to work for the latest release Cocos 2D : cocos2.0 http://www.cocos2d-iphone.org/download/ Can someone please check this and update the answer accordingly? Using the old version on xcode 4.6 generates far too many warnings! – Sagar Jun 13 '13 at 06:58
4

Create new project with cocos2d and find the libraries folder. Copy that libraries folder into your Xcode project. Provide Header Search Paths

- "Libraries/Chipmunk/objectivec/include"
- "Libraries/Chipmunk/chipmunk/include"
- "Libraries/kazmath/include"

Set other linker flag as - “-lz” Add below given frameworks

- QuartzCore.framework
- CoreText.framework
- AvFoundation.framework
- AudioToolbox.framework
- OpenAl.framework

Now compile the code. :)

Parul Garg
  • 355
  • 3
  • 14
1

This works with the older version of Cocos. For the newer version try this!

It worked for me!

http://www.cocos2d-iphone.org/forums/topic/adding-cocos2d-2-0-to-existing-iphone-project/#post-408352

Sagar
  • 555
  • 9
  • 24