//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer{public: virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(HelloWorld); voID callBackC(); voID callBackN(); voID callBackND();};#endif
//// HelloWorldScene.cpp//#include "HelloWorldScene.cpp"USING_NS_CC;CCScene* HelloWorld::scene(){ CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene;}bool HelloWorld::init(){ if ( !cclayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); float wIDthX = winSize.wIDth*0.5; float heightY = winSize.height*0.5; CCSprite *pSpr = CCSprite::create("Icon-57.png"); pSpr->setposition(ccp(pSpr->getContentSize().wIDth*0.5,heightY)); this->addChild(pSpr); /* 带“To”类代表对象移动到目标位置;带“By”类代表对象移动有时间或者速率效果,都是相对坐标,都可以执行反序动作“reverse” */ /* Cocos2d-x常用动作 */ // CCMoveto CCActionInterval *moveto = CCMoveto::create(5,ccp(wIDthX,heightY)); pSpr->runAction(moveto); // CCMoveBy CCActionInterval *moveBy = CCMoveBy::create(5,heightY)); CCActionInterval *actionByBack = moveBy->reverse(); pSpr->runAction(actionByBack); // CCScaleto CCActionInterval *scaleto = CCScaleto::create(2,2); pSpr->runAction(scaleto); // CCScaleBy CCActionInterval *scaleBy = CCScaleBy::create(2,2); CCActionInterval *actionByBack = scaleBy->reverse(); pSpr->runAction(actionByBack); // CCRotateto CCActionInterval *rotateto = CCRotateto::create(2,90); pSpr->runAction(rotateto); // CCRotateBy CCActionInterval *rotateBy = CCRotateBy::create(2,90); CCActionInterval *actionByBack = rotateBy->reverse(); pSpr->runAction(actionByBack); // CCSkewTo CCActionInterval *skewTo = CCSkewTo::create(2,10,10); pSpr->runAction(skewTo); // CCSkewBy CCActionInterval *skewBy = CCSkewBy::create(2,10); CCActionInterval *actionByBack = skewBy->reverse(); pSpr->runAction(actionByBack); // CCJumpTo CCActionInterval *jumpTo = CCJumpTo::create(2,ccp(300,200),50,4); pSpr->runAction(jumpTo); // CCJumpBy CCActionInterval *jumpBy = CCJumpBy::create(2,4); CCActionInterval *actionByBack = jumpBy->reverse(); pSpr->runAction(actionByBack); // ccBezIErConfig ccBezIErConfig bezIErCon; bezIErCon.controlPoint_1 = ccp(200,150); bezIErCon.controlPoint_2 = ccp(200,260); bezIErCon.endposition = ccp(340,100); // CCBezIErTo CCActionInterval *bezIErTo = CCBezIErTo::create(2,bezIErCon); pSpr->runAction(bezIErTo); CCActionInterval *bezIErBy = CCBezIErBy::create(2,bezIErCon); CCActionInterval *actionByBack = bezIErBy->reverse(); pSpr->runAction(actionByBack); // CCFadeIn CCActionInterval *fadeIn = CCFadeIn::create(2); pSpr->runAction(fadeIn); // CCFadeOut CCActionInterval *fadeOut = CCFadeOut::create(2); pSpr->runAction(fadeOut); // CCTintTo CCActionInterval *tintTo = CCTintTo::create(2,255,0); pSpr->runAction(tintTo); // CCTintBy CCActionInterval *tintBy = CCTintBy::create(2,0); CCActionInterval *actionByBack = tintBy->reverse(); pSpr->runAction(actionByBack); // CCBlink CCActionInterval *blink = CCBlink::create(2,3); pSpr->runAction(blink); // CCDelayTime CCActionInterval *delayTime = CCDelayTime::create(2); pSpr->runAction(delayTime); // CCOrbitCamera CCActionInterval *orbitCamera = CCOrbitCamera::create(3,1,45,180,90,0); pSpr->runAction(orbitCamera); // CCCardinalSpline CCPointArray *array = CCPointArray::create(20); array->addControlPoint(ccp(0,0)); array->addControlPoint(ccp(210,240)); array->addControlPoint(ccp(0,160)); array->addControlPoint(ccp(0,0)); // CCCardinalSplineto CCActionInterval *splineto = CCCardinalSplineto::create(4,array,0); pSpr->runAction(splineto); // CCCardinalSplineBy CCActionInterval *splineBy = CCCardinalSplineBy::create(4,0); CCActionInterval *actionByBack = splineBy->reverse(); pSpr->runAction(actionByBack); // CCCatmullRom CCPointArray *array = CCPointArray::create(5); array->addControlPoint(ccp(240,30)); array->addControlPoint(ccp(400,240)); array->addControlPoint(ccp(240,30)); // CCCatmullRomTo CCActionInterval *romTo = CCCatmullRomTo::create(2,array); pSpr->runAction(romTo); // CCCatmullRomBy CCActionInterval *romBy = CCCatmullRomBy::create(2,array); CCActionInterval *actionByBack = romBy->reverse(); pSpr->runAction(actionByBack); // CCFollw // 为了看到跟随效果,创建一个参考物 CCSprite *pSprT = CCSprite::create("Icon-57.png"); pSpr->setposition(ccp(420,40)); this->addChild(pSprT); CCActionInterval *moveto = CCMoveto::create(3,pSpr->getpositionY())); pSpr->runAction(moveto); CCFollow *follow = CCFollow::create(pSpr); this->runAction(follow); // CCEaseBounce CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); // CCEaseBounceIn CCActionInterval *easeBounceIn = CCEaseBounceIn::create(move); pSpr->runAction(easeBounceIn); // CCEaseBounceOut CCActionInterval *easeBounceOut = CCEaseBounceOut::create(move); pSpr->runAction(easeBounceOut); // CCEaseBounceInOut CCActionInterval *easeBounceInOut = CCEaseBounceInOut::create(move); pSpr->runAction(easeBounceInOut); // CCEaseBack CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); // CCEaseBackIn CCActionInterval *easeBackIn = CCEaseBackIn::create(move); pSpr->runAction(easeBackIn); // CCEaseBackOut CCActionInterval *easeBackOut = CCEaseBackOut::create(move); pSpr->runAction(easeBackOut); // CCEaseElastic CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); // CCEaseElasticIn CCActionInterval *easeElasticIn = CCEaseElasticIn::create(move); pSpr->runAction(easeElasticIn); // CCEaseElasticOut CCActionInterval *easeElasticOut = CCEaseElasticOut::create(move); pSpr->runAction(easeElasticOut); // CCEaseElasticInOut CCActionInterval *easeElasticInOut = CCEaseElasticInOut::create(move); pSpr->runAction(easeElasticInOut); // CCEaseExponential CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); // CCEaseExponentialin CCActionInterval *easeExponentialin = CCEaseExponentialin::create(move); pSpr->runAction(easeExponentialin); // CCEaseExponentialOut CCActionInterval *easeExponentialOut = CCEaseExponentialOut::create(move); pSpr->runAction(easeExponentialOut); // CCEaseExponentialinOut CCActionInterval *easeExponentialinOut = CCEaseExponentialinOut::create(move); pSpr->runAction(easeExponentialinOut); // CCEaseRateAction CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); CCActionInterval *easeRateAction = CCEaseRateAction::create(move,0.5); pSpr->runAction(easeRateAction); // CCEaseSine CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); // CCEaseSineIn CCActionInterval *easeSineIn = CCEaseSineIn::create(move); pSpr->runAction(easeSineIn); // CCEaseSineOut CCActionInterval *easeSineOut = CCEaseSineOut::create(move); pSpr->runAction(easeSineOut); // CCEaseSineInOut CCActionInterval *easeSineInOut = CCEaseSineInOut::create(move); pSpr->runAction(easeSineInOut); // CCSpeed CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); CCSpeed *speed = CCSpeed::create(move,10); pSpr->runAction(speed); // CCSpawn CCActionInterval *move = CCMoveto::create(5,pSpr->getpositionY())); CCActionInterval *scale = CCScaleto::create(2,3); CCActionInterval *rotate = CCRotateto::create(4,190); CCActionInterval *spawn = CCSpawn::create(move,scale,rotate,NulL); pSpr->runAction(spawn); // CCSequence CCActionInterval *move = CCMoveto::create(5,3); CCActionInterval *seq = CCSequence::create(move,NulL); pSpr->runAction(seq); // Reverse CCSequence CCActionInterval *move = CCMoveBy::create(5,pSpr->getpositionY())); CCActionInterval *scale = CCScaleBy::create(2,NulL); CCActionInterval *actionByBack = CCSequence::create(seq,seq->reverse(),NulL); pSpr->runAction(actionByBack); // CCRepeat CCActionInterval *move = CCMoveto::create(5,NulL); CCActionInterval *repeat = CCRepeat::create(seq,2); pSpr->runAction(repeat); // CCRepeatForever CCActionInterval *move = CCMoveto::create(5,NulL); CCActionInterval *repeatForever = CCRepeatForever::create(seq); pSpr->runAction(repeatForever); // CCCallFunc CCActionInterval *move = CCMoveto::create(1,pSpr->getpositionY())); CCCallFunc *funCall = CCCallFunc::create(this,callfunc_selector(HelloWorld::callBackC)); CCActionInterval *seq = CCSequence::create(move,funCall,NulL); pSpr->runAction(seq); // CCCallFuncN CCActionInterval *move = CCMoveto::create(1,pSpr->getpositionY())); CCCallFuncN *funCall = CCCallFuncN::create(this,callfuncN_selector(HelloWorld::callBackN)); CCActionInterval *seq = CCSequence::create(move,NulL); pSpr->runAction(seq); // CCCallFuncND CCActionInterval *move = CCMoveto::create(1,pSpr->getpositionY())); CCCallFuncND *funCall = CCCallFuncND::create(this,callfuncND_selector(HelloWorld::callBackND),(voID *)0xbebabeba); CCActionInterval *seq = CCSequence::create(move,NulL); pSpr->runAction(seq); return true;}voID HelloWorld::callBackC(){ cclOG("HelloWorld::callBackC");}voID HelloWorld::callBackN(){ cclOG("HelloWorld::callBackN");}voID HelloWorld::callBackND(){ cclOG("HelloWorld::callBackND");}
//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer{public: virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(HelloWorld);};#endif
//// HelloWorldScene.cpp//#include "HelloWorldScene.h"USING_NS_CC;CCScene* HelloWorld::scene(){ CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene;}bool HelloWorld::init(){ if ( !cclayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // Cocos2d-x常用特效 CCSprite *pSpr = CCSprite::create("Icon-57.png"); pSpr->setposition(ccp(pSpr->getContentSize().wIDth*0.5,170)); this->addChild(pSpr); // CCShaky3D CCActionInterval *shaky3D = CCShaky3D::create(5,CCSizeMake(16,12),true); pSpr->runAction(shaky3D); // CCShakyTiles3D CCActionInterval *shakyTiles3D = CCShakyTiles3D::create(5,true); pSpr->runAction(shakyTiles3D); // ccwaves CCActionInterval *waves = ccwaves::create(5,3,2.0f,true,true); pSpr->runAction(waves); // ccwavesTiles3D ccwavesTiles3D *wavesTiles3D = ccwavesTiles3D::create(5,2.0f); pSpr->runAction(wavesTiles3D); // CCFlipX3D CCActionInterval *flipX3D = CCFlipX3D::create(3); pSpr->runAction(flipX3D); // CCFlipY3D CCActionInterval *flipY3D = CCFlipY3D::create(3); pSpr->runAction(flipY3D); // cclens3D CCActionInterval *lens3D = cclens3D::create(5,ccp(winSize.wIDth*0.5,winSize.height*0.5),160); pSpr->runAction(lens3D); // CCRipple3D CCActionInterval *ripple3D = CCRipple3D::create(5,160,1.0f); pSpr->runAction(ripple3D); // ccliquID CCActionInterval *liquID = ccliquID::create(5,1.0f); pSpr->runAction(liquID); // CCTwirl CCActionInterval *twirl = CCTwirl::create(5,1.0f); pSpr->runAction(twirl); // CCShuffleTiles CCActionInterval *shuffleTiles = CCShuffleTiles::create(5,2); pSpr->runAction(shuffleTiles); // CCShatteredTiles3D CCActionInterval *shatteredTiles3D = CCShatteredTiles3D::create(5,25,true); pSpr->runAction(shatteredTiles3D); // CCFadeOutTRTiles CCActionInterval *fadeOutTRTTiles = CCFadeOutTRTiles::create(5,12)); pSpr->runAction(fadeOutTRTTiles); // CCFadeOutBLTiles CCActionInterval *fadeOutBLTiles = CCFadeOutBLTiles::create(5,12)); pSpr->runAction(fadeOutBLTiles); // CCFadeOutUpTiles CCActionInterval *fadeOutUpTiles = CCFadeOutUpTiles::create(5,12)); pSpr->runAction(fadeOutUpTiles); // CCFadeOutDownTiles CCActionInterval *fadeOutDownTiles = CCFadeOutDownTiles::create(5,12)); pSpr->runAction(fadeOutDownTiles); // CCTurnOffTiles CCActionInterval *turnOffTiles = CCTurnOffTiles::create(5,12)); pSpr->runAction(turnOffTiles); // CCJumpTiles3D CCActionInterval *jumpTiles3D = CCJumpTiles3D::create(5,2.0f); pSpr->runAction(jumpTiles3D); // CCSplitRows CCActionInterval *splitRows = CCSplitRows::create(5,3); pSpr->runAction(splitRows); // CCSplitCols CCActionInterval *splitCols = CCSplitCols::create(5,3); pSpr->runAction(splitCols); // CCPageTurn3D CCActionInterval *pageTurn3D = CCPageTurn3D::create(5,CCSizeMake(15,10)); pSpr->runAction(pageTurn3D); return true;}总结
以上是内存溢出为你收集整理的Cocos2d-x_CCAction(常用动作类)介绍全部内容,希望文章能够帮你解决Cocos2d-x_CCAction(常用动作类)介绍所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)