[iPhone-cocos2d]如何执行cocos2d官方自带test文件夹下面程序

Learning cocos2d with samples

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 CCSprite and CCSpriteSheet functionality 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:

  1. Open the cocos2d Xcode project
  2. Select the test target: Xcode -> Project -> Set Active Target -> eg: TransitionTest
  3. Make sure that the running executable is correct: Xcode -> Project -> Set Active Executable -> eg: TransitionTest
  4. Build and run: Xcode -> Build and run

Another quick way of doing it by customizing the toolbar:

  1. Xcode -> Right click on the toolbar -> Customize Toolbar
  2. Drag & drop the Active Target button to the toolbar
  3. 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:

  1. Select the TileMapTest target
  2. Make sure that the TileMapTest executable is selected
  3. Build & Run.
  4. Try all the subtests. The TileMapTest has more than 10 subtests. Eg: Hexagonal test, Isometric test, Orthogonal tests, read-write tile tests, etc…
  5. See the TileMapTest source code: tests/TileMapTest.m
  6. Modify the source code and go to step 2. :-)

最近常常有朋友问起,如何学习cocos2d,其实最好的文档莫过于官方的wiki,以及一些他所自带的例子。很多朋友不知道如何运行起来,其实cocos2d的博客上早就有了介绍了,步骤就那么5,6步而已,暂时不翻译了。挺简单的,贴过来加个中文的名字,至少搜索这个,就知道怎么弄了。还有就是推荐读那几个开源的游戏喽。不明白的翻我博客,本人曾翻译过很多cocos2d的wiki,希望能有所帮助吧。

http://alexliu.cnblogs.com

 

posted @ 2010-04-21 12:48  AlexLiu  阅读(1962)  评论(0编辑  收藏  举报