1. 程式人生 > >cocos2dx之閃爍效果-CCBlink

cocos2dx之閃爍效果-CCBlink

想讓自己建立的sprite有閃爍的效果 ,就需要利用到CAction的派生類:CCBlink了,詳細程式碼如下:

void MyActionCCBlinkLayer::initLayer() {
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSprite *spriteBlink = CCSprite::create("close.png");
    spriteBlink->setPosition(ccp(size.width / 2.0f, size.height / 2.0f));
    this->addChild(spriteBlink, 1);

    CCActionInterval *blinkAction = CCBlink::create(10, 20);
    //CCAction *action = CCRepeatForever::create(dynamic_cast<CCActionInterval *>(CCSequence::create(blinkAction, NULL)));
    spriteBlink->runAction(blinkAction);
}

完成閃爍效果!

注:那個閃爍的效果本想讓它無限次閃爍,暫時還沒有想到好的辦法,等找到答案了,再補全。