有时候,根据策划需求的效果,需要所有Sprte同时执行某一个动作,那么一般想到的是每个Sprite都执行型runAction,但是这样的话增加了代码量,我们会采用引擎提供的另一种方法,设置级联,调用setCascadeOpacityEnabled设置为true
看如下代码:
void ActionFade::onEnter() { ActionsDemo::onEnter(); centerSprites(2); //m_tamara->setOpacity( 0 ); CCActionInterval* action1 = CCFadeIn::create(1.0f); CCActionInterval* action1Back = action1->reverse(); CCActionInterval* action2 = CCFadeOut::create(1.0f); CCActionInterval* action2Back = action2->reverse(); m_tamara->addChild(m_kathia);///
m_tamara->setCascadeOpacityEnabled(true); //设置级联关系 CCActionInterval *move = CCMoveBy::create(0.5f,ccp(m_tamara->getPositionX() - 20,m_tamara->getPositionY())); CCActionInterval *back = move->reverse(); //m_tamara->runAction( CCSequence::create( action2,action1Back,NULL)); m_tamara->runAction(CCRepeatForever::create(CCSequence::create( move,back,NULL))); //m_kathia->runAction( CCSequence::create( action2,action2Back,NULL)); this->addChild(m_tamara); }原文链接:https://www.f2er.com/cocos2dx/342795.html