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

本文详细介绍cocos2d的内置测试用例作为学习资源,包括精灵、动作、菜单等功能测试,以及如何通过修改示例代码来自学Tiled地图等进阶技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Learning cocos2d with samples

Published by  on  in cocos2d9 Comments

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


转载于:https://www.cnblogs.com/pengyingh/articles/2388869.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值