0
我有一個按鈕,我需要成爲遊戲聲音的切換按鈕。我使用MenuSpriteItem類。如何更改MenuSpriteItem的圖像Cocos2d-x C++
auto menuSoundOn = Sprite::createWithSpriteFrameName("soundOn.png");
auto menuSoundOff = Sprite::createWithSpriteFrameName("soundOff.png");
auto menuSoundBtn = MenuItemSprite::create(menuSoundOn, menuSoundOff, CC_CALLBACK_1(LevelsLayer::shutSound, this));
menuSoundBtn->setTag(0);
_mainMenu = Menu::create(menuSoundBtn, nullptr);
this->addChild(_mainMenu);
//Then in my shutSound method
auto menuSoundBtn = _mainMenu->getChildByTag(0);
if (_ifSound){
_ifSound = false;
//Do some stuff to shut the sound
menuSoundBtn->setSelectedImage("noSound.png");
}
else{
_ifSound = true;
//Do some stuff to bring the sound back
menuSoundBtn->setSelectedImage("sound.png");
}
的問題是,從他與getChildByTag(0)方法母公司獲得BTN我收到的節點,其中文件根據,但setSelectedImage不是Node類的一部分,並且有一個錯誤告訴我的話,那麼從他們的父母中訪問MenuSpriteItem的正確方法是什麼?然後通過改變普通圖像來處理它們。
問候。