我正在尝试在游戏中制作日夜背景模式,并且我想在选项对话框中创建一个控制按钮,当我点击它时,所有背景都会更改而不退出对话框。我刚刚通过重新打开场景让它运行正常,但它也退出了选项对话框。
我有这样的initBackground()
方法
void MenuScene::initMenuBackground() {
setBackgroundMode();
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
//calculate system hour time
time_t now = time(0); // get time now
tm * ltm = localtime(&now);
double hour = ltm->tm_hour;
int curHourTime = (int) hour;
CCLOG("MenuScene hour is: %dh", curHourTime);
CCAnimation* caveAnim1 = CCAnimation::createWithSpriteFrames (senspark::Utils::createFramesArray("cave-%d.png", 3), 0.2f);
CCAnimation* caveAnim2 = CCAnimation::createWithSpriteFrames(senspark::Utils::createFramesArray("cave-%d.png", 3, 0, true), 0.2f);
cloudSpr->runAction(CCRepeatForever::create(CCSequence::create(CCMoveTo::create(30, ccp(winSize.width+100, cloudSpr->getPositionY())),
CCMoveTo::create(0, ccp(-100, cloudSpr->getPositionY())),
NULL)));
cloudNightSpr->runAction(CCRepeatForever::create(CCSequence::create(CCMoveTo::create(30, ccp(winSize.width+100, cloudSpr->getPositionY())),
CCMoveTo::create(0, ccp(-100, cloudSpr->getPositionY())),
NULL)));
//night
if ( ((curHourTime < 6 || curHourTime > 18) && (_isAuto==true)) || _isNight==true) {
caveNightSpr->runAction(CCRepeatForever::create(CCSequence::create(CCAnimate::create(caveAnim1),
CCAnimate::create(caveAnim2),
CCDelayTime::create(0.2f),
NULL)));
cloudSpr->setVisible(false);
startGoldSpr->setVisible(false);
backgroundSpr->setVisible(false);
backgroundSkySpr->setVisible(false);
backgroundNightSpr->setScaleX(CCDirector::sharedDirector()->getWinSize().width/designSize.width);
backgroundSkyNightSpr->setScaleX(CCDirector::sharedDirector()->getWinSize().width/designSize.width);
}
//daytime
if ( ((curHourTime > 6 && curHourTime < 18) && (_isAuto==true)) || _isDay==true) {
caveSpr->runAction(CCRepeatForever::create(CCSequence::create(CCAnimate::create(caveAnim1),
CCAnimate::create(caveAnim2),
CCDelayTime::create(0.2f),
NULL)));
cloudNightSpr->setVisible(false);
startGoldNightSpr->setVisible(false);
backgroundNightSpr->setVisible(false);
backgroundSkyNightSpr->setVisible(false);
backgroundSpr->setScaleX(CCDirector::sharedDirector()->getWinSize().width/designSize.width);
backgroundSkySpr->setScaleX(CCDirector::sharedDirector()->getWinSize().width/designSize.width);
}
我不知道如何刷新这些Sprite(删除然后重新调用它们)。 对不起,我的英语不好。任何帮助,将不胜感激。
答案 0 :(得分:0)
根据我的理解,您需要从场景中删除精灵并再次添加。
我希望能回答你的问题。
答案 1 :(得分:0)
最后找出我的问题,我可以使用mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png"));
更改精灵图像非常简单
不再需要删除然后再添加它。