djeetee
djeetee

Reputation: 1837

New iPhone cocos2d project with ARC

starting on a new project with Xcode 4.2 and cocos2d. I'd like to use ARC in my code and link cocos2d in as a static library.

Downloaded cocos2d from github and installed the new template.

Created a new cocos2d project however Xcode is not showing the usual ARC checkbox on the second dialogbox.

I'm assuming this is because the templates are Xcode 3 template?

Any thought on this would be appreciated.

thanks

UPDATE

since i posted this i downloaded cocos2d v2 and managed to compile the hello world with cocos2d as a static lib. the project was created using the cocos2d template and looks like it is set to use the LLVM comp v3 in 'Build Settings' but without ARC which is expected since the template did not give me the ARC checkbox.

I ran the Refactor to ARC and a few things needed fixing in the AppDelegate (.h & .m), the HelloWorldLayer.m and main.m which is still pre-ARC.

This tells me that the v2 cocos2 templates have not been updated and that's weird since v2 is supposed to be ARC'ed.

Am I missing something? should i be using different templates?

Kobold2d sound cool but is there a quick start guide?

thanks

Upvotes: 2

Views: 2561

Answers (3)

machineboy
machineboy

Reputation: 321

I was just doing this; Using the Edit->Refactor->Convert to Obj-C ARC tool in Xcode it was very quick to convert the basic Cocos2D 2.0 to ARC.

Just open a new project with the Cocos2D template, convert to ARC, select the 4 bottom files (.m) and save!

Upvotes: 0

alexhajdu
alexhajdu

Reputation: 400

I've written short step-by-step how to add static SimpleAudio cocos2d engine to your ARC project with Kobold2D - https://coderwall.com/p/jslwrg You can use it for all cocos2d library too...

Upvotes: 0

CodeSmile
CodeSmile

Reputation: 64477

If you want to use cocos2d-iphone with ARC consider using Kobold2D. Every project is ARC enabled by default, you don't have to do squat just install and start coding. Since it's the default option, you can be sure that the (improved) version of cocos2d-iphone in Kobold2D is tested well with ARC and contains a few additional ARC fixes.

Cocos2D as of v1.0.1 / 1.1 beta and 2.0 beta2 both do not support ARC out of the box (no ARC-enabled template project is available). This Tiny Tim games tutorial and this Ray Wenderlich tutorial teach you how to set up cocos2d-iphone properly to build as a static library so that you can enable ARC for your project's code.

Possible reasons why you don't see ARC as an option:

  • the project isn't set to use the "Apple LLVM Compiler 3.0"
  • you were looking for ARC but the Build Setting is actually named "Objective-C Automatic Reference Counting"

Note that cocos2d-iphone 1.0.1 (current stable release) to my knowledge is not compatible with ARC, but I believe v1.1 beta has added ARC support. Be sure to use either 1.1 beta or 2.0 beta.

Update to answer Update

Straight and simple: cocos2d-iphone as of today does NOT support ARC out of the box. There is no ARC-enabled template that cocos2d-iphone provides.

However, both v1.1 and 2.0 and newer can compile in an ARC-enabled project provided that you build cocos2d-iphone into a static library which has ARC disabled. That's what the Tiny Tim games tutorial is for.

In contrast all projects provided by Kobold2D have ARC enabled, and if you don't want to use ARC you just need to disable it in Build Settings. I hope you'll find the User's Guide helpful. There really isn't much to learn to get started with Kobold2D.

Upvotes: 4

Related Questions