cocos2dx 音效 粒子 数据存储

1.音效

引入头文件

#include "simpleAudioEngine.h"

命名空间

using namespace CocosDenshion;

 //创建一个背景
Size winSize = Director::getInstance()->getWinSize();
spriteTest = Sprite::create("bg.png");
spriteTest->setPosition(Vec2(winSize.width/,winSize.height/));
this->addChild(spriteTest); //
MenuItemSprite *itemSprite = MenuItemSprite::create(Sprite::create("1.png"), Sprite::create("8.png"), [&](Ref *spander){
CCLOG("点击了按钮");
//播放音效
SimpleAudioEngine::getInstance()->playEffect("bg.mp3");
});
itemSprite->setPosition(Vec2(winSize.width/,)); Menu *menu = Menu::create(itemSprite, NULL);
menu->setPosition(Vec2());
this->addChild(menu); //播放背景音乐
SimpleAudioEngine::getInstance()->playBackgroundMusic("bg.mp3",true);
return true; //提前加载音效(只加载不播放)
SimpleAudioEngine::getInstance()->preloadEffect("bg.mp3");

2.粒子系统

有个particle design 工具自定义粒子效果

 ParticleFire *ex = ParticleFire::create();
ex->setPosition(Vec2(, ));
this->addChild(ex);

3.数据存储

    //存储
UserDefault::getInstance()->setIntegerForKey("hp", );
UserDefault::getInstance()->flush(); //获取
int HP = UserDefault::getInstance()->getIntegerForKey("hp");
CCLOG("HP=%d",HP);
上一篇:暗黑战神! Unity3D网游ARPG实战案例


下一篇:Access to the path '....' is denied.解决方法