2012-04-19 14:35:52 +08:00
|
|
|
#include "CocosDenshionTest.h"
|
|
|
|
#include "cocos2d.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/GUI/CCControlExtension/CCControlSlider.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// android effect only support ogg
|
2014-01-09 09:50:02 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
2012-04-19 14:35:52 +08:00
|
|
|
#define EFFECT_FILE "effect2.ogg"
|
2014-01-09 09:50:02 +08:00
|
|
|
#elif( CC_TARGET_PLATFORM == CC_PLATFORM_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
|
|
|
|
2014-01-09 09:50:02 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MUSIC_FILE "music.mid"
|
2014-03-22 21:14:03 +08:00
|
|
|
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
|
|
|
#define MUSIC_FILE "background.wav"
|
2014-01-09 09:50:02 +08:00
|
|
|
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX )
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MUSIC_FILE "background.ogg"
|
2014-03-15 01:19:06 +08:00
|
|
|
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
#define MUSIC_FILE "background.caf"
|
2012-04-19 14:35:52 +08:00
|
|
|
#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-09-03 18:22:03 +08:00
|
|
|
class Button : public Node//, public TargetedTouchDelegate
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Button *createWithSprite(const char *filePath)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto b = new (std::nothrow) Button();
|
2013-06-22 04:01:00 +08:00
|
|
|
if (b && !b->initSpriteButton(filePath)) {
|
|
|
|
delete b;
|
2014-07-10 00:45:27 +08:00
|
|
|
b = nullptr;
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
2014-03-21 11:07:28 +08:00
|
|
|
b->autorelease();
|
2013-06-22 04:01:00 +08:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Button *createWithText(const char *text)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto b = new (std::nothrow) Button();
|
2013-06-22 04:01:00 +08:00
|
|
|
if (b && !b->initTextButton(text)) {
|
|
|
|
delete b;
|
2014-07-10 00:45:27 +08:00
|
|
|
b = nullptr;
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
2014-03-21 11:07:28 +08:00
|
|
|
b->autorelease();
|
2013-06-22 04:01:00 +08:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Button()
|
|
|
|
{
|
2013-09-03 18:22:03 +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()
|
2014-04-09 22:53:59 +08:00
|
|
|
: _child(nullptr)
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
// Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, 100, true);
|
|
|
|
|
|
|
|
// Register Touch Event
|
2013-10-23 11:27:24 +08:00
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
2013-09-03 18:22:03 +08:00
|
|
|
listener->setSwallowTouches(true);
|
|
|
|
|
|
|
|
listener->onTouchBegan = CC_CALLBACK_2(Button::onTouchBegan, this);
|
|
|
|
listener->onTouchEnded = CC_CALLBACK_2(Button::onTouchEnded, this);
|
|
|
|
listener->onTouchCancelled = CC_CALLBACK_2(Button::onTouchCancelled, this);
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
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)
|
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
_child = Label::createWithTTF(text, "fonts/arial.ttf", 16);
|
2013-06-22 04:01:00 +08:00
|
|
|
addChild(_child);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
bool touchHits(Touch *touch)
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
|
|
|
const Rect area(0, 0, _child->getContentSize().width, _child->getContentSize().height);
|
2013-07-26 06:53:24 +08:00
|
|
|
return area.containsPoint(_child->convertToNodeSpace(touch->getLocation()));
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
bool onTouchBegan(Touch *touch, Event *event)
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
CC_UNUSED_PARAM(event);
|
|
|
|
const bool hits = touchHits(touch);
|
2013-06-22 04:01:00 +08:00
|
|
|
if (hits)
|
2013-07-22 14:28:19 +08:00
|
|
|
scaleButtonTo(0.9f);
|
2013-06-22 04:01:00 +08:00
|
|
|
return hits;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void onTouchEnded(Touch *touch, Event *event)
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
CC_UNUSED_PARAM(event);
|
|
|
|
const bool hits = touchHits(touch);
|
2013-06-22 04:01:00 +08:00
|
|
|
if (hits && _onTriggered)
|
|
|
|
_onTriggered();
|
|
|
|
scaleButtonTo(1);
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void onTouchCancelled(Touch *touch, Event *event)
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
CC_UNUSED_PARAM(event);
|
2013-06-22 04:01:00 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto ret = new (std::nothrow) AudioSlider(direction);
|
2013-06-22 04:01:00 +08:00
|
|
|
if (ret && !ret->init()) {
|
|
|
|
delete ret;
|
2014-07-10 00:45:27 +08:00
|
|
|
ret = nullptr;
|
2013-06-22 04:01:00 +08:00
|
|
|
}
|
2014-03-21 11:07:28 +08:00
|
|
|
ret->autorelease();
|
2013-06-22 04:01:00 +08:00
|
|
|
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) {
|
2014-04-09 23:31:05 +08:00
|
|
|
_lblMinValue = Label::createWithTTF(buffer, "fonts/arial.ttf", 8);
|
2013-06-22 04:01:00 +08:00
|
|
|
addChild(_lblMinValue);
|
|
|
|
if (_direction == Vertical)
|
2014-08-28 11:41:18 +08:00
|
|
|
_lblMinValue->setPosition(12.0, -50.0);
|
2013-06-22 04:01:00 +08:00
|
|
|
else
|
2014-08-28 11:41:18 +08:00
|
|
|
_lblMinValue->setPosition(-50, 12.0);
|
2013-06-22 04:01:00 +08:00
|
|
|
} else {
|
|
|
|
_lblMinValue->setString(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buffer, "%.2f", maxValue);
|
|
|
|
if (!_lblMaxValue) {
|
2014-04-09 23:31:05 +08:00
|
|
|
_lblMaxValue = Label::createWithTTF(buffer, "fonts/arial.ttf", 8);
|
2013-06-22 04:01:00 +08:00
|
|
|
addChild(_lblMaxValue);
|
|
|
|
if (_direction == Vertical)
|
2014-08-28 11:41:18 +08:00
|
|
|
_lblMaxValue->setPosition(12.0, 50.0);
|
2013-06-22 04:01:00 +08:00
|
|
|
else
|
2014-08-28 11:41:18 +08:00
|
|
|
_lblMaxValue->setPosition(50, 12.0);
|
2013-06-22 04:01:00 +08:00
|
|
|
} else {
|
|
|
|
_lblMaxValue->setString(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AudioSlider(Direction direction)
|
|
|
|
: _direction(direction)
|
2014-04-09 22:53:59 +08:00
|
|
|
, _slider(nullptr)
|
|
|
|
, _lblMinValue(nullptr)
|
|
|
|
, _lblMaxValue(nullptr)
|
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;
|
2014-03-26 23:33:58 +08:00
|
|
|
Label *_lblMinValue;
|
|
|
|
Label *_lblMaxValue;
|
2013-06-22 04:01:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CocosDenshionTest::CocosDenshionTest()
|
|
|
|
: _soundId(0),
|
|
|
|
_musicVolume(1),
|
|
|
|
_effectsVolume(1),
|
2014-04-09 22:53:59 +08:00
|
|
|
_sliderPitch(nullptr),
|
|
|
|
_sliderPan(nullptr),
|
|
|
|
_sliderGain(nullptr),
|
|
|
|
_sliderEffectsVolume(nullptr),
|
|
|
|
_sliderMusicVolume(nullptr)
|
2013-06-22 04:01:00 +08:00
|
|
|
{
|
|
|
|
addButtons();
|
|
|
|
addSliders();
|
|
|
|
schedule(schedule_selector(CocosDenshionTest::updateVolumes));
|
|
|
|
|
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
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblMusic = Label::createWithTTF("Control Music", "fonts/arial.ttf", 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
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblSound = Label::createWithTTF("Control Effects", "fonts/arial.ttf", 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
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblPitch = Label::createWithTTF("Pitch", "fonts/arial.ttf", 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
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblPan = Label::createWithTTF("Pan", "fonts/arial.ttf", 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
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblGain = Label::createWithTTF("Gain", "fonts/arial.ttf", 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
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblEffectsVolume = Label::createWithTTF("Effects Volume", "fonts/arial.ttf", 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
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto lblMusicVolume = Label::createWithTTF("Music Volume", "fonts/arial.ttf", 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;
|
2014-08-28 11:41:18 +08:00
|
|
|
node->setPosition(percentageX * size.width, percentageY * size.height);
|
2013-06-22 04:01:00 +08:00
|
|
|
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()
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto layer = new (std::nothrow) CocosDenshionTest();
|
2013-07-23 08:25:44 +08:00
|
|
|
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
|
|
|
}
|