- 浏览: 1028047 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (675)
- ios (214)
- android-course (5)
- unity3d (7)
- cocos2d (36)
- html5 (3)
- game (5)
- android (42)
- java (57)
- php (12)
- 创业 (10)
- SEO (3)
- 架构 (2)
- 数据库 (3)
- 产品设计 (9)
- 操作系统 (10)
- Web前端 (11)
- 其他 (50)
- GAE (1)
- mac os (8)
- Open Source (2)
- 序列号 (10)
- C (2)
- database (2)
- 算法 (6)
- 设计模式 (1)
- photoshop (1)
- 3dmax (1)
- maya (1)
- opengl (3)
- 游戏设计 (1)
- 趋势 (1)
- cocos2d-x (4)
- shell (3)
- c++ (30)
- lua (5)
- flash (1)
- spring (3)
- mysql (4)
- Git (6)
- xmpp (1)
- cocos2dx (14)
- mac (2)
- 编程规范 (2)
- windows (1)
- linux (5)
- coocs2dx (1)
- ubuntu (2)
- aws (1)
- OPENGLES (1)
- 原画 (1)
最新评论
-
jlees:
Best mobile app testing tool pc ...
iOS + XCode 4 + GHUnit = Mobile TDD+Continuous testing -
ipanda:
楼主,能否给一个Micro CloudFoundry的虚机或者 ...
Cloud Foundry使用及开发向导 -
love_zongming:
谢谢分享。。
visio2007序列号 -
雨花台舞水:
你这才是枪文把
套在 360 黑匣子外面的黑盒子:你被技术型枪稿吓到了么? -
hugh.wang:
改天试试
Mac版魔兽争霸3 1.24e下载
While Cocos2D is compatible with ARC, simply enabling ARC in the project’s Build Setting will throw several hundreds of errors in your face. Cocos2D doesn’t provide ARC-enabled project templates. Thus this tutorial about how to enable ARC in a newly created Cocos2D Xcode Project.
While none of these steps are overly difficult, you’ll notice there’s plenty of steps to perform. Unavoidably, and on the off chance you don’t already know, I’d like to recommend Kobold2Dto you if you want to write ARC enabled Cocos2D apps. Because none of the steps below, really zero, zilch, nada, niente, keine are necessary to enable ARC in Kobold2D. That’s because it ships with 15 template projects all of which have ARC enabled out of the box. And Kobold2D 2.0 with cocos2d-iphone 2.0 is just around the corner.
Self-advertisment aside, these steps are tested with cocos2d-iphone v2.0 but should also work with cocos2d-iphone v1.1 – but admittedly I haven’t tested the process with the v1.1 version. If you find anything that’s not quite working with v1.1 please leave a comment. Preferably with the solution, that’ll be awesome!
Install Xcode, Cocos2D, and the Cocos2D Xcode Templates
Let’s first check that you have all the prerequisites. With iOS devices selling like Playboys in the 70s these days, there’s got to be those who haven’t gotten to install Xcode or download Cocos2D yet. And for everyone else this is a version-check and a reminder to upgrade their tools and cocos2d frequently. The latter being particularly simple if you’d been using Kobold2D. Just saying.
- Download and Install Xcode 4. Now might be a good time to upgrade if you’re not on Xcode 4.2 – because there’s no ARC for you without at least Xcode 4.2.
- Download Cocos2D and extract the cocos2d-iphone-****.tar file by double-clicking it. The filename varies depending on the cocos2d version.
- Open Terminal.app and enter:
./path-to-cocos2d-iphone/install-templates.sh -fNote: The path-to-cocos2d-iphone needs to be replaced with the actual path to the cocos2d directory. For example, if you are using Safari and extracted the filecocos2d-iphone-2.0-rc0a.tar where Safari downloaded it, then this command should work for you: ./Downloads/cocos2d-iphone-2.0-rc0a/install-templates.sh -f.
Note that the leading dot is essential, without it you’ll most likely get a “No such file or directory” error.The install-templates.sh script will install the cocos2d-iphone Xcode templates. You have to run this script each time you download a new Cocos2D version to make sure that newly created cocos2d projects use the latest cocos2d version.
The template files are copied to the user’s Developer directory which is~/Library/Developer/Xcode/Templates. This is the directory you want to browse to in Finder if you ever wanted to delete the cocos2d Xcode templates. Perhaps to remove older version files or in case the install script fails with a permission issue.
The -f switch forces the script to replace any existing cocos2d template files, so that you don’t get any errors should you have previously installed the cocos2d Xcode templates.
ARC-ifying the Cocos2D code of the Template Projects
First we are refactoring the Cocos2D code away from your project and into a static library, so that your ARC-enabled code and the non-ARC cocos2d code can work happily together. If you were to enable ARC without separating the cocos2d source code the compiler would not be very happy. The Cocos2D codebase may be compatible but it’s not compliant with ARC, meaning Cocos2D itself is not using ARC and must be compiled with ARC disabled.
The following steps are the same for all Cocos2D Xcode Project Templates. I chose the Box2D template but you can apply the same steps to any of the other templates as well.
- Open Xcode (duh!)
- Create a new project, for example by selecting from the menu: File -> New -> Project…
- Select the desired cocos2d Xcode Template: Box2D, Chipmunk or no physics for either iOS or Mac OS X.
4. Click Next and give the new project an appropriate name and save it anywhere (but remember where).
5.Build & Run the project to verify that it’s working. You never know.
Warning: Some recommend to use the -fno-objc-arc Compiler Flag to disable ARC on a per-source-file basis. This is only helpful if you have very few source code files which require this flag where an extra static library target would be overkill. Since you’ll have to add the flag to each cocos2d source code file individually – one-by-one – and there being anywhere between 100 and 150 source files, I strongly discourage going down this road. Plus it will be a maintenance nightmare whenever you upgrade cocos2d.
10.Once created, the cocos2d-library target is selected and the Build Settings pane is shown. You need to navigate the Build Settings to make two changes to the Search Paths section. The easiest way to find these settings is by entering “search” to the search filter textbox in the upper right corner of the Build Settings pane.
Set the Always Search User Paths setting to Yes and set the User Header Search Paths to the somewhat cryptic ./** string.
Note: You can edit the User Header Search Paths setting in two ways, one by clicking it twice with a delay between the clicks – this allows you to enter the text directly. Alternatively you can double-click the field which brings up an additional dialog with a checkbox in it. In that case, either enter just a dot and click the checkbox, or enter the full string ./** but do not check the checkbox. Otherwise you might end up with the string ./**/** which will cause compiler errors. Be sure to verify the string is correct after the edit dialog closes, since Xcode might change the string depending on whether the checkbox is checked.
Warning: The search path ./** is a quick & dirty short-hand for “search the project’s folder and all of its subfolders recursively”. This works fine as long as any header file you create or add to your project does not have the same name as a header file in thelibs folder. For example, you must not add a header file named CCNode.h to your project, because the compiler will be confused which CCNode.h to use – the one from your project or the one provided by cocos2d-iphone. This applies to all files in the path, including those that aren’t referenced by the Xcode project.
11.Select the original target of the project. That means the one that was already there, the one that’s building your app, not the cocos2d-library target you just added. Select the Build Phasestab and expand the Link Binary With Libraries list.
12.Click on the + button at the bottom of the list, select the libcocos2d-library.a file and click theAdd button. This will link the cocos2d library code to your project’s target.
13.Now it’s time to re-add the cocos2d files. Use File -> Add Files to “name-of-project”… to bring up the file dialog. Navigate to and select the libs folder. Make sure the Destinationcheckbox is unchecked and the Create groups for any added folders radio button is selected. Finally verify that the cocos2d-library target is the only target whose checkbox is checked before clicking the Add button.
14.Build and run to make sure everything works now that the cocos2d code was separated into a static library.
Enabling ARC in your project
Now that the cocos2d code is separated from your project’s code, you can use the built-in Xcode ARC conversion tool to update the project template code to use ARC. This will also enable the appropriate Build Settings.
1.From the Xcode menu choose Edit -> Refactor -> Convert to Objective-C ARC…. This brings up a dialog where you can select the targets to convert. Select only your app’s target but not the cocos2d-library target. Then click on Check.
2.Xcode will build your code with ARC enabled and then present you with a wizard that helps you convert the project’s code to ARC. Read the text and click Next.
3.Xcode will show a dialog that allows you to review the changes it is about to make. You can safely accept all of these changes.
4.Build, run and rejoice: Your project’s code is now ARC-enabled!
Cleaning up (optional)
When you created the cocos2d-library target it also added three source code files to the project that you don’t need. You can safely delete (trash) the cocos2d-library group and all the files in it.
You only need to make a small change to the Build Settings of the cocos2d-library target. Locate the Prefix Header Build Setting, select it and press the Delete key so that the Prefix Header setting is empty. Alternatively just keep the prefix header file and only delete the two other files (cocos2d-library.h and .m).
Enjoy your ARC, WOOF, WOOF, GRRRRRR!
This should make it straightforwd for everyone to enable ARC in a Cocos2D project. Of course you can always just get Kobold2D and not concern yourself with these nasty technical things at all.
I hope you enjoyed this tutorial. Please leave a comment if you found any discrepancies, specifically since newer cocos2d or Xcode versions might behave slightly different. I’d also appreciate it if you’d tweet, like or plus-one this article if you liked it. Thank you!
转载自:http://www.learn-cocos2d.com/2012/04/enabling-arc-cocos2d-project-howto-stepbystep-tutorialguide/
发表评论
-
Mac上安装Protocol Buffers
2016-09-18 11:29 8131.下载文件 (http://code.google.com ... -
webview点击获取图片
2016-04-01 17:12 822UILongPressGestureRecognizer * ... -
hexo 自动部署脚步
2016-03-29 21:17 927echo "===============star ... -
自定义navigationItem.leftBarButtonItem后,系统默认的手势滑动失效解决方案
2016-03-01 18:01 1275自定义navigationItem.le ... -
UITextView autolayout 高度自适应
2016-02-15 23:26 1404UITextView *t = [[UITextView ... -
腾讯敏捷框架TAPD》研究
2015-11-19 20:47 1416这篇文档是研究心得 ... -
ios image 压缩
2015-11-06 12:09 832- (UIImage *)_scaleToSize:(UII ... -
iphone分辨率图解
2015-11-04 17:33 549iphone分辨率图解 -
IOS中获取各种文件的目录路径的方法
2015-09-24 12:10 643iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储 ... -
Customizing Navigation Bar and Status Bar in iOS 7
2015-08-17 20:23 1600Like many of you, I have been ... -
GCD 深入理解:第一部分
2015-07-24 14:49 763本文翻译自 http://www.raywenderlich ... -
Mac上的抓包工具Charles
2015-05-06 01:09 5313Mac上的抓包工具Charles 分类: IO ... -
如何移除发布版本中的NSLog输出
2015-05-04 20:27 741Phone开发中会经常使用NSLog将一些运行信息输出到终端 ... -
xcode4的环境变量,Build Settings参数,workspace及联编设置
2015-03-27 11:23 920一、xcode4中的环境变量 $(BUILT_PROD ... -
数字签名是什么?
2014-11-25 16:58 610http://www.ruanyifeng.com/blog/ ... -
让你的Xcode更加高效
2014-10-29 00:16 511http://www.tairan.com/archives/ ... -
我所经历的“余额宝”的那些故事
2014-06-08 01:05 749“余额宝”经过不到 ... -
代码手写UI,xib和StoryBoard间的博弈,以及Interface Builder的一些小技巧
2014-05-31 01:25 790最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍 ... -
WWDC 2013 Session笔记 - iOS7中的多任务
2014-05-31 01:24 658这是我的WWDC2013系列笔记中的一篇,完整的笔记列表 ... -
Protect your game assets (currently Cocos2D only)
2014-05-20 15:54 921Creating a game is hard work ...
相关推荐
Cocos2d-JS 是一个基于 JavaScript 的游戏开发框架,它是 Cocos2d-x 的 JavaScript 版本。这个“Cocos2d-JS---demo”压缩包包含的是使用 Cocos2d-JS 开发的游戏或应用的示例,用于展示其功能和效果。通过将这些 demo...
该资源主要用于cocos2d-x中Value与json字符串的相互转换,提供从json文件读取为cocos2d::Value,cocos2d::Value写入到文件,cocos2d::Value转换为json字符串,json字符串转换为cocos2d::Value。json字符串转换成cocos...
《cocos2d-x -2.0-rc2-x-2.0.1:跨平台手机游戏开发的强大引擎》 cocos2d-x是一个广泛使用的开源游戏开发框架,专为构建2D游戏、演示和其它图形交互应用而设计。这个框架的版本"2.0-rc2-x-2.0.1"是其发展过程中的一...
Cocos2d-x 是一个开源的游戏开发框架,主要用于创建2D游戏、图形界面以及实时应用程序。这个框架基于C++,并且提供了多种语言接口,包括Python、JavaScript和Lua,让开发者可以选择他们熟悉的编程语言进行游戏开发。...
《基于cocos2d-2.0-x-2.0.3的游戏实例——魔塔(win版)详解》 在游戏开发的世界里,cocos2d-x是一个广受欢迎的开源跨平台2D游戏引擎,它基于C++,并提供了Python和Lua等语言的绑定,使得开发者能够快速构建游戏。...
cocos引擎老版本下载集合(cocos2d-x-2.2.1 - 3.5),分别有cocos2d-x-3.5、cocos2d-x-3.4、cocos2d-x-3.2、cocos2d-x-2.2.6、cocos2d-x-2.2.2和cocos2d-x-2.2.1。
资源名称:Cocos2d-x实战:JS卷——Cocos2d-JS开发内容简介:本书是介绍Cocos2d-x游戏编程和开发技术书籍,介绍了使用Cocos2d-JS中核心类、瓦片地图、物理引擎、音乐音效、数据持久化、网络通信、性能优化、多平台...
《cocos2d-x与第三方库的IPv6适配及WebSocket技术详解》 在移动游戏开发领域,cocos2d-x是一个广泛使用的2D游戏引擎,它为开发者提供了丰富的功能和高效的性能。随着网络环境的变化,IPv6逐渐成为主流,对于cocos2d...
cocos引擎老版本下载集合(cocos2d-x-2.2.1 - 3.5),分别有cocos2d-x-3.5、cocos2d-x-3.4、cocos2d-x-3.2、cocos2d-x-2.2.6、cocos2d-x-2.2.2和cocos2d-x-2.2.1。
《cocos2d-x与libluajit.a:解决设备崩溃问题》 在移动游戏开发领域,cocos2d-x是一个广泛使用的开源2D游戏引擎,它基于C++,并且支持Lua脚本语言,为开发者提供了高效且便捷的游戏制作工具。然而,在实际开发过程...
cocos2d-x第三方库 该存储库包含与cocos2d-x捆绑在一起的第三方库(二进制)的源代码。 对于cocos2d-x开发人员和/或想要: 生成特定库的更新版本(例如:将libpng 1.6.2升级到1.6.14) 将cocos2d-x移植到其他平台...
《cocos2dx 4.0 引擎与 Metal 支持详解》 在游戏开发领域,cocos2dx 是一款广泛使用的开源游戏引擎,它基于 C++ 开发,为开发者提供了高效、跨平台的游戏开发解决方案。随着技术的迭代,cocos2dx 4.0 引擎引入了更...
《使用cocos2d-x-2.0-2.0.4开发的简单跨平台益智类魔塔小游戏》 cocos2d-x是一个开源的游戏开发框架,它基于C++,支持多平台,包括iOS、Android、Windows以及Mac OS等。在本项目中,开发者利用cocos2d-x 2.0.4版本...
1. 角色控制:通过监听用户输入,结合cocos2d-x的MoveTo、MoveBy动作类,实现角色的平移和跳跃。 2. 碰撞检测:利用Box2D物理引擎或自定义的矩形碰撞检测,判断角色与其他对象的碰撞,触发相应事件。 3. 敌人AI:...
开发cocos2d-20.0-x-2.0.4用的jar包,这个是最新的。懒人必备!!
《Cocos2d-x实战:C++卷(2版)源代码》这本书是关于使用Cocos2d-x游戏引擎进行游戏开发的专业指南。Cocos2d-x是一个开源的、跨平台的游戏开发框架,广泛应用于iOS、Android、Windows等多个操作系统。本书以C++语言...
《Cocos2d-js与IntelliJ IDEA的高效开发整合》 Cocos2d-js是一款强大的游戏开发框架,它结合了Cocos2d-x的性能和JavaScript的易用性,使得开发者可以使用JavaScript进行跨平台的游戏开发。在本文中,我们将深入探讨...
《Cocos2d-x实战 JS卷》是一本深入探讨Cocos2d-x游戏开发的专著,主要聚焦于使用JavaScript语言进行游戏编程。Cocos2d-x是一个开源的游戏开发框架,广泛应用于移动设备和桌面平台,支持iOS、Android、Windows等多...