Chapter 6 - How to Play Music and Sound Effect
In this chapter, we would add background music to the game and play sound effect when the hero fires bullets.
Because there’s so few codes to add that we could say a little more about audio engine here. Cocos2d-x has wrapped SimpleAudioEngine to cross platforms. In our game, we are able to play music and sound effect using only one line of codes. It is so convenient. Of course, audio formats supported in different platform are different, about this issue, you could refer to http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Audio_formats_supported_by_CocosDenshion_on_different_platforms.
In fact, cocos2d-iphone includes the cocosDenshion library, and the library offers three layers of interfaces: CDSoundEngine->CDAudioManager->SimpleAudioEngine, but its realization totally relies on OpenAL. About OpenAL, it is not a standard of Khronos Group, it is an open source of Creative, which could be realize by software and hardware. So far, OpenAL is hardware realized only by Apple’s products, so in other platforms, we couldn’t provide supports for the lower layers of cocosDenshion, but we support the top layer which is used most commonly by the developers.
Now let’s get right to the issues.
First, copy the sound files background-music-aac.wav and pew-pew-lei.wav to the Resource directory. We use wav here because wav is supported in all platforms and these two files have been included in the Cocos2dSimpleGame project, you could download them from the bottom of this page.
Then include SimpleaudioEngine.h in HelloWorldScene.cpp.
1// cpp with cocos2d-x
2#include "SimpleAudioEngine.h"
Add the background music in init().
1// cpp with cocos2d-x
2CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(
3"background-music-aac.wav", true);
And play the sound effect in ccTouchesEnded() when the bullet is fired.
1// cpp with cocos2d-x
2CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
3"pew-pew-lei.wav");
Ok, the audio addition is completed now.
Chapter 6 - How to Play Music and Sound Effect的更多相关文章
- Cocos2d-x之Sound
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 音效简介: 1.1 在游戏开发的过程中除了华丽的界面,生动的动画之外,适当的音效也是重要的一部分 1.2 游戏中的声音分为两类,一类是音乐 ...
- 脚本AI与脚本引擎
Scripted AI and Scripting Engines 脚本AI与脚本引擎 This chapter discusses some of the techniques you can us ...
- 用Phaser实现Flappy Bird 游戏
How to Make a Flappy Bird in HTML5 With Phaser - Part 1 Flappy Bird is a nice little game with easy ...
- Sprite Kit 入门教程
Sprite Kit 入门教程 Ray Wenderlich on September 30, 2013 Tweet 这篇文章还可以在这里找到 英语, 日语 If you're new here, ...
- Approaching the Fun Factor in Game Design
I recently did some research on this and talked to Dr. Clayton Lewis (computer Scientist in Residenc ...
- iOS开发——UI篇OC篇&SpriteKit详解
SpriteKit详解 SpriteKit,iOS/Mac游戏制作的新纪元 这是我的WWDC2013系列笔记中的一篇,完整的笔记列表请参看这篇总览.本文仅作为个人记录使用,也欢迎在许可协议范围内转载或 ...
- Android UI 设计准则
Design Principles 设计准则 These design principles were developed by and for the Android User Experienc ...
- (转)Apple Push Notification Services in iOS 6 Tutorial: Part 1/2
转自:http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 Upda ...
- Sprite Kit教程:制作一个通用程序 2
注1:本文译自Sprite Kit Tutorial: Making a Universal App: Part 2 目录 动画的定义:可行性 属性列表 添加游戏逻辑 添加音效 何去何从 上一篇文章中 ...
随机推荐
- delphi xe5 android 开发数据访问手机端(一)
上几片文章我们把供手机端调用的web服务完成,接下来实现手机端调用webservices获取数据 1.新建firemonkey mobile application 2.选择blank applica ...
- bzoj 2402: 陶陶的难题II 二分答案维护凸包
2402: 陶陶的难题II Time Limit: 40 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 68 Solved: 45[Submi ...
- 纯手工全删除域内最后一个EXCHANGE--How to Manually Uninstall Last Exchange 2010 Server from Organization
http://www.itbigbang.com/how-to-manually-uninstall-last-exchange-2010-server-from-organization/ 没办法, ...
- 创建虚拟桌面的代码(重启桌面进程)(使用GetThreadDesktop,CreateDesktop,SetThreadDesktop等函数)
在upk 里挖坟得来,有兴趣查查这几个函数... #include "windows.h" #pragma comment(lib,"user32.lib") ...
- 最全的JAVA源码整合下载
http://www.360doc.com/content/14/0602/00/11407612_382890953.shtml http://www.360doc.com/content/14/0 ...
- 监控持有sql和被堵塞的sql
Session 1: mysql> start transaction; Query OK, 0 rows affected (0.00 sec) mysql> update Client ...
- C# winform 导出导入Excel/Doc 完整实例教程[网上看到的]
还真没做过winform的导出导入,今天上网百度了一下.结果--- 所以还是我自己写个吧.之前做过web的,半搬半做就OK. 1添加引用:Aspose.Cells.dll(我们就叫工具包吧,可以从网上 ...
- 【转】iOS开发:开发证书知识点总结
原文网址:http://www.jianshu.com/p/9c166a5e4930 1. Error: An App ID with identifier "*" is not ...
- Android-webView的loadUrl
1 //打开本包内asset目次下的test.html文件 wView.loadUrl(" file:///android_asset/test.html "); 2 //打开本地 ...
- Maven学习:常用mvn命令
转自:http://blog.csdn.net/lfsfxy9/article/details/12200915 Maven 在线: <span style="font-family: ...