转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25513031
缓冲动作
一、TestCpp实例ActionsTest 模块中SpriteEaseExponential指数缓冲动作
程序代码:
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 *sp1 = CCSprite::create("cpp1.png"); sp1->setScale(0.5f); sp1->setPosition(ccp(100, 100)); this->addChild(sp1); CCSprite *sp2 = CCSprite::create("cpp2.png"); sp2->setScale(0.5f); sp2->setPosition(ccp(visibleSize.width/2-100, visibleSize.height/2)); this->addChild(sp2); CCSprite *sp3 = CCSprite::create("cpp3.png"); sp3->setScale(0.5f); sp3->setPosition(ccp(visibleSize.width/2+100, visibleSize.height/2)); this->addChild(sp3); /******************************SpriteEaseExponential指数缓冲*********************************/ CCActionInterval* move = CCMoveBy::create(3, ccp(visibleSize.width/2, 0));;//移动动作 CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseExponentialIn::create((CCActionInterval*)(move->copy()->autorelease()) );//移动时由慢到快(指数加速) CCActionInterval* move_ease_in_back = move_ease_in->reverse(); CCActionInterval* move_ease_out = CCEaseExponentialOut::create((CCActionInterval*)(move->copy()->autorelease()) );//移动时由慢到快(指数减数) CCActionInterval* move_ease_out_back = move_ease_out->reverse(); CCDelayTime *delay = CCDelayTime::create(2.0f);//3s后动画回放 CCSequence* seq1 = CCSequence::create(move, delay, move_back, CCCA(delay), NULL); CCSequence* seq2 = CCSequence::create(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); CCSequence* seq3 = CCSequence::create(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); sp1->runAction(seq1); sp2->runAction(seq2); sp3->runAction(seq3); return true; }
二、TestCpp实例ActionsTest 模块中SpriteEaseSine赛因缓冲动作
程序代码:
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 *sp1 = CCSprite::create("cpp1.png"); sp1->setScale(0.5f); sp1->setPosition(ccp(100, 100)); this->addChild(sp1); CCSprite *sp2 = CCSprite::create("cpp2.png"); sp2->setScale(0.5f); sp2->setPosition(ccp(visibleSize.width/2-100, visibleSize.height/2)); this->addChild(sp2); CCSprite *sp3 = CCSprite::create("cpp3.png"); sp3->setScale(0.5f); sp3->setPosition(ccp(visibleSize.width/2+100, visibleSize.height/2)); this->addChild(sp3); /******************************SpriteEaseSine赛因缓冲*********************************/ CCActionInterval* move = CCMoveBy::create(3, ccp(visibleSize.width/2, 0));//移动动作 CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseSineIn::create((CCActionInterval*)(move->copy()->autorelease()) );//移动时由慢到快(赛因加速) CCActionInterval* move_ease_in_back = move_ease_in->reverse(); CCActionInterval* move_ease_out = CCEaseSineOut::create((CCActionInterval*)(move->copy()->autorelease()) );//移动时由快到慢(赛因减速) CCActionInterval* move_ease_out_back = move_ease_out->reverse(); CCDelayTime *delay = CCDelayTime::create(3.0f);//3s后动画回放 CCSequence* seq1 = CCSequence::create(move, delay, move_back, CCCA(delay), NULL); CCSequence* seq2 = CCSequence::create(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); CCSequence* seq3 = CCSequence::create(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); sp1->runAction(seq1); sp2->runAction(seq2); sp3->runAction(seq3); return true; }