2012-04-19 14:35:52 +08:00
|
|
|
#include "CocosDenshionTest.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "SimpleAudioEngine.h"
|
2013-06-22 04:01:00 +08:00
|
|
|
#include "GUI/CCControlExtension/CCControlSlider.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// android effect only support ogg
|
2013-06-22 04:01:00 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFOR_ANDROID)
|
2012-04-19 14:35:52 +08:00
|
|
|
#define EFFECT_FILE "effect2.ogg"
|
2013-06-22 04:01:00 +08:00
|
|
|
#elif( CC_TARGET_PLATFORM == CC_PLATFOR_MARMALADE)
|
2012-04-19 14:35:52 +08:00
|
|
|
#define EFFECT_FILE "effect1.raw"
|
|
|
|
#else
|
|
|
|
#define EFFECT_FILE "effect1.wav"
|
2013-06-22 04:01:00 +08:00
|
|
|
#endif // CC_PLATFOR_ANDROID
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFOR_WIN32)
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MUSIC_FILE "music.mid"
|
2013-06-22 04:01:00 +08:00
|
|
|
#elif (CC_TARGET_PLATFORM == CC_PLATFOR_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFOR_LINUX )
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MUSIC_FILE "background.ogg"
|
|
|
|
#else
|
|
|
|
#define MUSIC_FILE "background.mp3"
|
2013-06-22 04:01:00 +08:00
|
|
|
#endif // CC_PLATFOR_WIN32
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
USING_NS_CC;
|
2012-04-19 14:35:52 +08:00
|
|
|
using namespace CocosDenshion;
|
|
|
|
|
|
|
|
#define LINE_SPACE 40
|
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
class Button : public Node, public TargetedTouchDelegate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Button *createWithSprite(const char *filePath)
|
|
|
|
{
|
|
|
|
auto b = new Button();
|
|
|
|
if (b && !b->initSpriteButton(filePath)) {
|
|
|
|
delete b;
|
|
|
|
b = NULL;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Button *createWithText(const char *text)
|
|
|
|
{
|
|
|
|
auto b = new Button();
|
|
|
|
if (b && !b->initTextButton(text)) {
|
|
|
|
delete b;
|
|
|
|
b = NULL;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Button()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getTouchDispatcher()->removeDelegate(this);
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void onTriggered(const std::function<void(void)> &onTriggered)
|
|
|
|
{
|
|
|
|
_onTriggered = onTriggered;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Button()
|
|
|
|
: _child(NULL)
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, 100, true);
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool initSpriteButton(const char *filePath)
|
|
|
|
{
|
|
|
|
_child = Sprite::create(filePath);
|
|
|
|
addChild(_child);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initTextButton(const char *text)
|
|
|
|
{
|
|
|
|
_child = LabelTTF::create(text, "Arial", 16);
|
|
|
|
addChild(_child);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool touchHits(Touch *pTouch)
|
|
|
|
{
|
|
|
|
const Rect area(0, 0, _child->getContentSize().width, _child->getContentSize().height);
|
|
|
|
return area.containsPoint(_child->convertToNodeSpace(pTouch->getLocation()));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent)
|
|
|
|
{
|
|
|
|
CC_UNUSED_PARAM(pEvent);
|
|
|
|
const bool hits = touchHits(pTouch);
|
|
|
|
if (hits)
|
2013-07-22 14:28:19 +08:00
|
|
|
scaleButtonTo(0.9f);
|
2013-06-22 04:01:00 +08:00
|
|
|
return hits;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ccTouchEnded(Touch *pTouch, Event *pEvent)
|
|
|
|
{
|
|
|
|
CC_UNUSED_PARAM(pEvent);
|
|
|
|
const bool hits = touchHits(pTouch);
|
|
|
|
if (hits && _onTriggered)
|
|
|
|
_onTriggered();
|
|
|
|
scaleButtonTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent)
|
|
|
|
{
|
|
|
|
CC_UNUSED_PARAM(pEvent);
|
|
|
|
scaleButtonTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void scaleButtonTo(float scale)
|
|
|
|
{
|
2013-07-22 14:28:19 +08:00
|
|
|
auto action = ScaleTo::create(0.1f, scale);
|
2013-06-22 04:01:00 +08:00
|
|
|
action->setTag(900);
|
|
|
|
stopActionByTag(900);
|
|
|
|
runAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *_child;
|
|
|
|
std::function<void(void)> _onTriggered;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioSlider : public Node
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 04:01:00 +08:00
|
|
|
public:
|
|
|
|
enum Direction {
|
|
|
|
Vertical,
|
|
|
|
Horizontal
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
static AudioSlider *create(Direction direction)
|
|
|
|
{
|
|
|
|
auto ret = new AudioSlider(direction);
|
|
|
|
if (ret && !ret->init()) {
|
|
|
|
delete ret;
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2012-10-23 17:48:50 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
float getValue() const
|
|
|
|
{
|
|
|
|
return _slider->getValue();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
void setValue(float minValue, float maxValue, float value)
|
|
|
|
{
|
|
|
|
_slider->setMinimumValue(minValue);
|
|
|
|
_slider->setMaximumValue(maxValue);
|
|
|
|
_slider->setValue(value);
|
|
|
|
|
|
|
|
char buffer[32];
|
|
|
|
|
|
|
|
sprintf(buffer, "%.2f", minValue);
|
|
|
|
if (!_lblMinValue) {
|
|
|
|
_lblMinValue = LabelTTF::create(buffer, "Arial", 8);
|
|
|
|
addChild(_lblMinValue);
|
|
|
|
if (_direction == Vertical)
|
2013-07-12 14:11:55 +08:00
|
|
|
_lblMinValue->setPosition(Point(12.0, -50.0));
|
2013-06-22 04:01:00 +08:00
|
|
|
else
|
2013-07-12 14:11:55 +08:00
|
|
|
_lblMinValue->setPosition(Point(-50, 12.0));
|
2013-06-22 04:01:00 +08:00
|
|
|
} else {
|
|
|
|
_lblMinValue->setString(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buffer, "%.2f", maxValue);
|
|
|
|
if (!_lblMaxValue) {
|
|
|
|
_lblMaxValue = LabelTTF::create(buffer, "Arial", 8);
|
|
|
|
addChild(_lblMaxValue);
|
|
|
|
if (_direction == Vertical)
|
2013-07-12 14:11:55 +08:00
|
|
|
_lblMaxValue->setPosition(Point(12.0, 50.0));
|
2013-06-22 04:01:00 +08:00
|
|
|
else
|
2013-07-12 14:11:55 +08:00
|
|
|
_lblMaxValue->setPosition(Point(50, 12.0));
|
2013-06-22 04:01:00 +08:00
|
|
|
} else {
|
|
|
|
_lblMaxValue->setString(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AudioSlider(Direction direction)
|
|
|
|
: _direction(direction)
|
|
|
|
, _slider(NULL)
|
|
|
|
, _lblMinValue(NULL)
|
|
|
|
, _lblMaxValue(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
bool init()
|
|
|
|
{
|
|
|
|
_slider = extension::ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
|
|
|
|
_slider->setScale(0.5);
|
|
|
|
if (_direction == Vertical)
|
|
|
|
_slider->setRotation(-90.0);
|
|
|
|
addChild(_slider);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Direction _direction;
|
|
|
|
extension::ControlSlider *_slider;
|
|
|
|
LabelTTF *_lblMinValue;
|
|
|
|
LabelTTF *_lblMaxValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
CocosDenshionTest::CocosDenshionTest()
|
|
|
|
: _soundId(0),
|
|
|
|
_musicVolume(1),
|
|
|
|
_effectsVolume(1),
|
|
|
|
_sliderPitch(NULL),
|
|
|
|
_sliderPan(NULL),
|
|
|
|
_sliderGain(NULL),
|
|
|
|
_sliderEffectsVolume(NULL),
|
|
|
|
_sliderMusicVolume(NULL)
|
|
|
|
{
|
|
|
|
addButtons();
|
|
|
|
addSliders();
|
|
|
|
schedule(schedule_selector(CocosDenshionTest::updateVolumes));
|
|
|
|
|
|
|
|
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
|
|
|
|
|
|
// std::string testItems[] = {
|
|
|
|
// "unload effect",
|
|
|
|
// "pause effect",
|
|
|
|
// "resume effect",
|
|
|
|
// "pause all effects",
|
|
|
|
// "resume all effects",
|
|
|
|
// "stop all effects"
|
|
|
|
// };
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// preload background music and effect
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->preloadBackgroundMusic( MUSIC_FILE );
|
|
|
|
SimpleAudioEngine::getInstance()->preloadEffect( EFFECT_FILE );
|
2013-06-22 04:01:00 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// set default volume
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->setEffectsVolume(0.5);
|
|
|
|
SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.5);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CocosDenshionTest::~CocosDenshionTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocosDenshionTest::onExit()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onExit();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-22 10:06:14 +08:00
|
|
|
SimpleAudioEngine::end();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
void CocosDenshionTest::addButtons()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 04:01:00 +08:00
|
|
|
LabelTTF *lblMusic = LabelTTF::create("Control Music", "Arial", 24);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblMusic, 0.25f, 0.9f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
Button *btnPlay = Button::createWithText("play");
|
|
|
|
btnPlay->onTriggered([]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->playBackgroundMusic(MUSIC_FILE, true);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnPlay, 0.1f, 0.75f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnStop = Button::createWithText("stop");
|
|
|
|
btnStop->onTriggered([]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->stopBackgroundMusic();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnStop, 0.25f, 0.75f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnRewindMusic = Button::createWithText("rewind");
|
|
|
|
btnRewindMusic->onTriggered([]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->rewindBackgroundMusic();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnRewindMusic, 0.4f, 0.75f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnPause = Button::createWithText("pause");
|
|
|
|
btnPause->onTriggered([]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnPause, 0.1f, 0.65f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnResumeMusic = Button::createWithText("resume");
|
|
|
|
btnResumeMusic->onTriggered([]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnResumeMusic, 0.25f, 0.65f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnIsPlayingMusic = Button::createWithText("is playing");
|
|
|
|
btnIsPlayingMusic->onTriggered([]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
if (SimpleAudioEngine::getInstance()->isBackgroundMusicPlaying())
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("background music is playing");
|
|
|
|
else
|
|
|
|
CCLOG("background music is not playing");
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnIsPlayingMusic, 0.4f, 0.65f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
LabelTTF *lblSound = LabelTTF::create("Control Effects", "Arial", 24);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblSound, 0.75f, 0.9f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnPlayEffect = Button::createWithText("play");
|
|
|
|
btnPlayEffect->onTriggered([this]() {
|
|
|
|
const float pitch = _sliderPitch->getValue();
|
|
|
|
const float pan = _sliderPan->getValue();
|
|
|
|
const float gain = _sliderGain->getValue();
|
2013-07-19 07:30:19 +08:00
|
|
|
_soundId = SimpleAudioEngine::getInstance()->playEffect(EFFECT_FILE, false, pitch, pan, gain);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnPlayEffect, 0.6f, 0.8f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnPlayEffectInLoop = Button::createWithText("play in loop");
|
|
|
|
btnPlayEffectInLoop->onTriggered([this]() {
|
|
|
|
const float pitch = _sliderPitch->getValue();
|
|
|
|
const float pan = _sliderPan->getValue();
|
|
|
|
const float gain = _sliderGain->getValue();
|
2013-07-19 07:30:19 +08:00
|
|
|
_soundId = SimpleAudioEngine::getInstance()->playEffect(EFFECT_FILE, true, pitch, pan, gain);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnPlayEffectInLoop, 0.75f, 0.8f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnStopEffect = Button::createWithText("stop");
|
|
|
|
btnStopEffect->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->stopEffect(_soundId);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnStopEffect, 0.9f, 0.8f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnUnloadEffect = Button::createWithText("unload");
|
|
|
|
btnUnloadEffect->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->unloadEffect(EFFECT_FILE);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnUnloadEffect, 0.6f, 0.7f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnPauseEffect = Button::createWithText("pause");
|
|
|
|
btnPauseEffect->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->pauseEffect(_soundId);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnPauseEffect, 0.75f, 0.7f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnResumeEffect = Button::createWithText("resume");
|
|
|
|
btnResumeEffect->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->resumeEffect(_soundId);
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnResumeEffect, 0.9f, 0.7f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnPauseAll = Button::createWithText("pause all");
|
|
|
|
btnPauseAll->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnPauseAll, 0.6f, 0.6f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnResumeAll = Button::createWithText("resume all");
|
|
|
|
btnResumeAll->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnResumeAll, 0.75f, 0.6f);
|
2013-06-22 04:01:00 +08:00
|
|
|
|
|
|
|
Button *btnStopAll = Button::createWithText("stop all");
|
|
|
|
btnStopAll->onTriggered([this]() {
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->stopAllEffects();
|
2013-06-22 04:01:00 +08:00
|
|
|
});
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(btnStopAll, 0.9f, 0.6f);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
void CocosDenshionTest::addSliders()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 04:01:00 +08:00
|
|
|
auto lblPitch = LabelTTF::create("Pitch", "Arial", 14);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblPitch, 0.67f, 0.4f);
|
2013-06-22 04:01:00 +08:00
|
|
|
_sliderPitch = AudioSlider::create(AudioSlider::Horizontal);
|
|
|
|
_sliderPitch->setValue(0.5, 2, 1);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(_sliderPitch, 0.85f, 0.4f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
auto lblPan = LabelTTF::create("Pan", "Arial", 14);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblPan, 0.67f, 0.3f);
|
2013-06-22 04:01:00 +08:00
|
|
|
_sliderPan = AudioSlider::create(AudioSlider::Horizontal);
|
|
|
|
_sliderPan->setValue(-1, 1, 0);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(_sliderPan, 0.85f, 0.3f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
auto lblGain = LabelTTF::create("Gain", "Arial", 14);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblGain, 0.67f, 0.2f);
|
2013-06-22 04:01:00 +08:00
|
|
|
_sliderGain = AudioSlider::create(AudioSlider::Horizontal);
|
|
|
|
_sliderGain->setValue(0, 1, 1);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(_sliderGain, 0.85f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
auto lblEffectsVolume = LabelTTF::create("Effects Volume", "Arial", 14);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblEffectsVolume, 0.62f, 0.5f);
|
2013-06-22 04:01:00 +08:00
|
|
|
_sliderEffectsVolume = AudioSlider::create(AudioSlider::Horizontal);
|
|
|
|
_sliderEffectsVolume->setValue(0, 1, 1);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(_sliderEffectsVolume, 0.85f, 0.5f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
auto lblMusicVolume = LabelTTF::create("Music Volume", "Arial", 14);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(lblMusicVolume, 0.12f, 0.5f);
|
2013-06-22 04:01:00 +08:00
|
|
|
_sliderMusicVolume = AudioSlider::create(AudioSlider::Horizontal);
|
|
|
|
_sliderMusicVolume->setValue(0, 1, 1);
|
2013-07-22 14:28:19 +08:00
|
|
|
addChildAt(_sliderMusicVolume, 0.35f, 0.5f);
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
2012-10-23 17:48:50 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
void CocosDenshionTest::addChildAt(Node *node, float percentageX, float percentageY)
|
|
|
|
{
|
|
|
|
const Size size = VisibleRect::getVisibleRect().size;
|
|
|
|
node->setPosition(Point(percentageX * size.width, percentageY * size.height));
|
|
|
|
addChild(node);
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
void CocosDenshionTest::updateVolumes(float)
|
|
|
|
{
|
|
|
|
const float musicVolume = _sliderMusicVolume->getValue();
|
|
|
|
if (fabs(musicVolume - _musicVolume) > 0.001) {
|
|
|
|
_musicVolume = musicVolume;
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(_musicVolume);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 04:01:00 +08:00
|
|
|
const float effectsVolume = _sliderEffectsVolume->getValue();
|
|
|
|
if (fabs(effectsVolume - _effectsVolume) > 0.001) {
|
|
|
|
_effectsVolume = effectsVolume;
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->setEffectsVolume(_effectsVolume);
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CocosDenshionTestScene::runThisTest()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = new CocosDenshionTest();
|
|
|
|
addChild(layer);
|
|
|
|
layer->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|