Beispiel #1
0
void PauseLayer::musicButtonOnTouch(Ref* sender,CheckBox::EventType type)
{
    //播放音效
    SoundBLL::getInstance()->playEffect(kButtonSound);
    
    auto box=(CheckBox*)sender;
    box->runAction(Sequence::create(ScaleTo::create(0.1, 0.8),ScaleTo::create(0.1, 1.2),ScaleTo::create(0.1, 1.0), NULL));
    //声音状态
    auto soundBLL=SoundBLL::getInstance();
    bool bSound=soundBLL->isMusicMute();
    soundBLL->setMusicMute(!bSound);
}
Beispiel #2
0
// on "init" you need to initialize your instance
bool PauseLayer::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !PopBase::init() )
    {
        return false;
    }
    
    m_RootNode = static_cast<Layout*>(CSLoader::createNode("PauseLayer.csb"));
    this->addChild(m_RootNode);
    
    auto effectBtn=dynamic_cast<CheckBox*>(Helper::seekWidgetByName(m_RootNode, "CheckBox_yinxiao"));
    if (effectBtn) {
        effectBtn->addEventListener(CC_CALLBACK_2(PauseLayer::effectButtonOnTouch, this));
    }
    auto musicBtn=dynamic_cast<CheckBox*>(Helper::seekWidgetByName(m_RootNode, "CheckBox_yinyue"));
    if (musicBtn) {
        musicBtn->addEventListener(CC_CALLBACK_2(PauseLayer::musicButtonOnTouch, this));
    }
    auto Button_Resume=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_RESUME"));
    if (Button_Resume) {
        Button_Resume->addTouchEventListener(CC_CALLBACK_2(PauseLayer::Button_Resume_BtnOnTouch, this));
    }
    auto Button_QUIT=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_QUIT"));
    if (Button_QUIT) {
        Button_QUIT->addTouchEventListener(CC_CALLBACK_2(PauseLayer::Button_QUIT_BtnOnTouch, this));
    }
    
    //声音状态
    auto soundBLL=SoundBLL::getInstance();
    musicBtn->setSelected(soundBLL->isMusicMute());
    effectBtn->setSelected(soundBLL->isEffectMute());
    
    return true;
}
Beispiel #3
0
/**
 * Streams music from a cluster file.
 * @param musicId the id of the music to stream
 * @param loop true if the music is to loop back to the start
 * @return RD_OK or an error code
 */
int32 Sound::streamCompMusic(uint32 musicId, bool loop) {
	Common::StackLock lock(_mutex);

	int cd = _vm->_resman->getCD();

	if (loop)
		_loopingMusicId = musicId;
	else
		_loopingMusicId = 0;

	int primary = -1;
	int secondary = -1;

	// If both music streams are active, one of them will have to go.

	if (_music[0] && _music[1]) {
		int32 fade0 = _music[0]->isFading();
		int32 fade1 = _music[1]->isFading();

		if (!fade0 && !fade1) {
			// Neither is fading. This shouldn't happen, so just
			// pick one and be done with it.
			primary = 0;
		} else if (fade0 && !fade1) {
			// Stream 0 is fading, so pick that one.
			primary = 0;
		} else if (!fade0 && fade1) {
			// Stream 1 is fading, so pick that one.
			primary = 1;
		} else {
			// Both streams are fading. Pick the one that is
			// closest to silent.
			if (ABS(fade0) < ABS(fade1))
				primary = 0;
			else
				primary = 1;
		}

		delete _music[primary];
		_music[primary] = NULL;
	}

	// Pick the available music stream. If no music is playing it doesn't
	// matter which we use.

	if (_music[0] || _music[1]) {
		if (_music[0]) {
			primary = 1;
			secondary = 0;
		} else {
			primary = 0;
			secondary = 1;
		}
	} else
		primary = 0;

	// Don't start streaming if the volume is off.
	if (isMusicMute()) {
		return RD_OK;
	}

	if (secondary != -1)
		_music[secondary]->fadeDown();
	SoundFileHandle *fh = (cd == 1) ? &_musicFile[0] : &_musicFile[1];
	fh->inUse = true;

	MusicInputStream *tmp = new MusicInputStream(cd, fh, musicId, loop);

	if (tmp->isReady()) {
		_music[primary] = tmp;
		fh->inUse = false;
		return RD_OK;
	} else {
		fh->inUse = false;
		delete tmp;
		return RDERR_INVALIDFILENAME;
	}
}