cocos2dx 3.3 跑酷游戏 声音的加入
来源:互联网 发布:n的阶乘算法 编辑:程序博客网 时间:2024/06/17 03:38
声音同样使用了单例模式:
声音直接在其他文件中使用;
将声音头文件包进去,在与金币碰撞,跳起和落下时播放
#pragma once#include "cocos2d.h"#include "SimpleAudioEngine.h"//使用声音要包含的头文件#include "Def.h"//参数设定头文件USING_NS_CC;using namespace CocosDenshion;//使用声音要包含的命名空间class Sounder{public:static Sounder *getInstance();bool init();void playGold();//播放金币声音void playTouch();//播放跳起和落声音void playBackground();//播放背景void playJump();//弃。。。private:Sounder();~Sounder();static Sounder *shareSounder;};
#include "Sounder.h"Sounder* Sounder::shareSounder = NULL;Sounder *Sounder::getInstance(){if (shareSounder != NULL){shareSounder = new Sounder;//shareSounder->init();//改为在主场景中调用,避免第一次初始化时读取文件的卡顿}return shareSounder;}Sounder::Sounder(){}Sounder::~Sounder(){if (shareSounder){delete shareSounder;}}bool Sounder::init()//预读取声音文件{SimpleAudioEngine::getInstance()->preloadBackgroundMusic(MUSIC_BACKGROUND);SimpleAudioEngine::getInstance()->preloadEffect(MUSIC_GOLD);SimpleAudioEngine::getInstance()->preloadEffect(MUSIC_JUMP);SimpleAudioEngine::getInstance()->preloadEffect(MUSIC_TOUCH);return true;}void Sounder::playBackground(){SimpleAudioEngine::getInstance()->playBackgroundMusic(MUSIC_BACKGROUND,true);}void Sounder::playGold(){SimpleAudioEngine::getInstance()->playEffect(MUSIC_GOLD);}void Sounder::playJump(){SimpleAudioEngine::getInstance()->playEffect(MUSIC_JUMP);}void Sounder::playTouch(){SimpleAudioEngine::getInstance()->playEffect(MUSIC_TOUCH);}
0 0
- cocos2dx 3.3 跑酷游戏 声音的加入
- 加入游戏声音
- cocos2dx 3.3 跑酷游戏的编写
- cocos2dx 3.3 跑酷游戏的编写 游戏层
- 【Cocos2dx】跑酷游戏
- cocos2dx 3.3 跑酷游戏 人物的创建
- cocos2dx 3.3 跑酷游戏 信息层
- cocos2dx 3.3 跑酷游戏 背景层
- cocos2dx 图片加入游戏后会模糊
- 基于cocos2dx,在android的游戏中加入google play game排行榜。
- 我的cocos2dx游戏
- 【cocos2dx-3.0beta-制作flappybird】终于要来正戏了—游戏层的设计和小鸟的加入
- Cocos2dx游戏开发系列笔记7:一个简单的跑酷游戏《萝莉快跑》的消化(附下载)
- ios 加入声音效果
- 给MFC加入声音
- cocos2dx播放声音学习
- cocos2dx Audio声音引擎
- cocos2dx中的声音
- 添加电脑到域
- 仿IOS7的两种对话框
- 《数据结构》课程设计题目
- WebView显示的网页在大分辨率屏下被放大的解决方法
- objective中方法和函数区别
- cocos2dx 3.3 跑酷游戏 声音的加入
- Go语言知识积累:windows开发环境搭建
- 归并排序求逆序对
- HDU 5074 Hatsune Miku
- HDU steps 1.2.7 AC Me
- 数字识别
- linux system函数使用详解
- SlackTextViewController开源:强大的iOS文字输入解决方案
- 黑马程序员-----java基础 多线程