效果图:
程序源码:
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
CCSprite *flare = CCSprite::create("flare.jpg");
flare->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
this->addChild(flare);
flare->setOpacity(0);// 设置初始透明度
flare->setRotation(-120);// 设置初始角度
flare->setScale(0.2f);// 设置初始缩小倍
// 由不透明到透明渐变
CCActionInterval *opacityAnim = CCFadeTo::create(0.5f, 255);
CCActionInterval *opacDim = CCFadeTo::create(1.0f, 0);
// 0.7s放大1.2倍, 放大动作减速
CCActionInterval *bigAnim = CCScaleBy::create(0.7f, 1.2f, 1.2f);
CCEaseSineOut *biggerEase = CCEaseSineOut::create(bigAnim);
//0.5s移动新位置,移动动作减速
CCActionInterval *moveAnim = CCMoveBy::create(0.5f, ccp(328, 0));
CCEaseSineOut *moveEase = CCEaseSineOut::create(moveAnim);
// 角度旋转90',角度旋转速度,指数减速
CCActionInterval *roteAnim = CCRotateBy::create(2.5f, 90);
CCEaseExponentialOut * rotateEase = CCEaseExponentialOut::create(roteAnim);
// 放大到原大小
CCScaleTo *bigger = CCScaleTo::create(0.5f, 1);
// 执行动画和回调函数切换GameLayer场景
flare->runAction(CCSequence::create(opacityAnim, biggerEase, opacDim, NULL));//初始化sprite设置完成后,显示sprite,然后放大0.7s持续放大1.2倍,再设置为透明
flare->runAction(moveEase);//0.5s持续减速移动到新的位置
flare->runAction(rotateEase);//指数减速2.5s持续旋转90'
flare->runAction(bigger);//最后恢复原大小
return true;
}