然后修改HelloWorldLayer层,当计数器改变的时候,就调用Hud类的方法,这样就可以相应地更新Hud类了。
编译并运行,如果一切ok,你将会在屏幕右下角看到统计忍者吃西瓜的Label。
来点音效和音乐
如果没有很cool的音效和背景音乐的话,这就不能算作是一个完整的游戏教程了。
增加音效和音乐非常简单,只需在HelloWolrdScene.m作如下修改:
//
At top of file
#import " SimpleAudioEngine.h "
// At top of init for HelloWorld layer
[[SimpleAudioEngine sharedEngine] preloadEffect: @" pickup.caf " ];
[[SimpleAudioEngine sharedEngine] preloadEffect: @" hit.caf " ];
[[SimpleAudioEngine sharedEngine] preloadEffect: @" move.caf " ];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic: @" TileMap.caf " ];
// In case for collidable tile
[[SimpleAudioEngine sharedEngine] playEffect: @" hit.caf " ];
// In case of collectable tile
[[SimpleAudioEngine sharedEngine] playEffect: @" pickup.caf " ];
// Right before setting player position
[[SimpleAudioEngine sharedEngine] playEffect: @" move.caf " ];
#import " SimpleAudioEngine.h "
// At top of init for HelloWorld layer
[[SimpleAudioEngine sharedEngine] preloadEffect: @" pickup.caf " ];
[[SimpleAudioEngine sharedEngine] preloadEffect: @" hit.caf " ];
[[SimpleAudioEngine sharedEngine] preloadEffect: @" move.caf " ];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic: @" TileMap.caf " ];
// In case for collidable tile
[[SimpleAudioEngine sharedEngine] playEffect: @" hit.caf " ];
// In case of collectable tile
[[SimpleAudioEngine sharedEngine] playEffect: @" pickup.caf " ];
// Right before setting player position
[[SimpleAudioEngine sharedEngine] playEffect: @" move.caf " ];
现在,我们的忍者可以开怀大吃了!
何去何从?
这个系列的教程,就此完结了。距离上次翻译时间长了点。通过这个教程的学习,你对cocos2d里面的tiled map的使用,应该有一个非常好的理解了。这里有这个教程的完整源代码。
接下来,我会接着翻译下一篇,是原作者的一个朋友写的,这个系列教程的终结版:《加入敌人和战斗:如果使用cocos2d制作基于tiled的地图:第三部分》。
如果你看了这个教程,有什么好的意见或建议,可以自由发言,谢谢!