阅读: 112 评论: 0 作者: AlexLiu 发表于 2010-04-21 12:48 原文链接
Arguably the most unknown cocos2d feature is the tests/samples.
cocos2d contains almost a test for each feature that it has. These tests are grouped by component. eg:
- Sprite Test: It tests the
CCSpriteandCCSpriteSheetfunctionality like anchorPoint, visibility, parenting, reordering, honor Transform, etc… - Action Test: It tests the
CCMove, CCRotate, CCTint, CCCamera, CCSequence, CCSpawn, etc.. - Menu Test: It tests all kind of menus
- CocosDenshion: It tests the Sound Engine
- Chipmunk Accel Touch Test: It tests integration with Chipmunk physics engine using accelerometer and multi touches.
- Particle Test: It tests all kind of particles (quad particles, point particles, sun, meteor, galaxy, smoke, fire, etc…)
- etc…
Although these tests were coded for testing purposes they can also be used as examples. Not only they use the API in the recommended way, but some of them, also contain useful tips in the commentaries.
In order to run the tests, you should do:
- Open the cocos2d Xcode project
- Select the test target: Xcode -> Project -> Set Active Target -> eg: TransitionTest
- Make sure that the running executable is correct: Xcode -> Project -> Set Active Executable -> eg: TransitionTest
- Build and run: Xcode -> Build and run
Another quick way of doing it by customizing the toolbar:
- Xcode -> Right click on the toolbar -> Customize Toolbar
- Drag & drop the Active Target button to the toolbar
- Drag & drop the Active Executable button to the toolbar
The source code of the samples are in the tests subdirectory.
So, let’s say you want to learn how to use Tiled maps. What you should do is:
- Select the TileMapTest target
- Make sure that the TileMapTest executable is selected
- Build & Run.
- Try all the subtests. The TileMapTest has more than 10 subtests. Eg: Hexagonal test, Isometric test, Orthogonal tests, read-write tile tests, etc…
- See the TileMapTest source code: tests/TileMapTest.m
- Modify the source code and go to step 2.
最近常常有朋友问起,如何学习cocos2d,其实最好的文档莫过于官方的wiki,以及一些他所自带的例子。很多朋友不知道如何运行起来,其实cocos2d的博客上早就有了介绍了,步骤就那么5,6步而已,暂时不翻译了。挺简单的,贴过来加个中文的名字,至少搜索这个,就知道怎么弄了。还有就是推荐读那几个开源的游戏喽。不明白的翻我博客,本人曾翻译过很多cocos2d的wiki,希望能有所帮助吧。
最新新闻:
· Flash vs. HTML5:RIA领域当前的混战(2010-05-12 22:30)
· 腾讯第一季总收入42.261亿元 同比增长68.7%(2010-05-12 22:22)
· 刘翔官网引门户PK 马化腾3000万砸倒张朝阳(2010-05-12 22:11)
· i4i专利被判有效 微软侵权赔偿2.4亿美元(2010-05-12 22:07)
· 亚马逊收集Kindle电子书中标记和笔记数据(2010-05-12 22:05)
编辑推荐:Web高性能开发系列随笔
