新建工程,testAction
修改HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayer
{
public:
// Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
virtual bool init();
// there's no 'id' in cpp, so we recommend to return the class instance pointer
static cocos2d::CCScene* scene();
// preprocessor macro for "static create()" constructor ( node() deprecated )
CREATE_FUNC(HelloWorld);
void callbackC();
void callbackN(CCNode* sender);
void callbackND(CCNode* sender,void* data);
};
#endif // __HELLOWORLD_SCENE_H__
修改HelloWorldScene.cpp#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
#define ActionMarco 48
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSprite *sp=CCSprite::create("Icon.png");
sp->setPosition(ccp(150, 150));
addChild(sp,0,922);
switch (ActionMarco) {
case 1:
{
//------------------CCMoveBy
CCActionInterval *moveBy=CCMoveBy::create(5, ccp(300,200));//5秒运动到300,200
CCActionInterval *actionByBack=moveBy->reverse(); //反向运动
sp->runAction(actionByBack);
}
break;
case 2:
{
//--------------CCScaleTo
CCActionInterval *scaleTo= CCScaleTo::create(2, 2);
sp->runAction(scaleTo);
}
break;
case 3:
{
//-------------CCScaleBy
CCActionInterval *scaleBy=CCScaleBy::create(2, 2);
CCActionInterval *actionByBack=scaleBy->reverse();
sp->runAction(actionByBack);
}
break;
case 4:
{
//-------------CCRotateTo
CCActionInterval *rotateTo=CCRotateTo::create(2, 90);
sp->runAction(rotateTo);
}
break;
case 5:
{
//--------------CCSkewTo
CCActionInterval *skewTo=CCSkewTo::create(2, 10, 10);
sp->runAction(skewTo);
}
break;
case 6:
{
//------------CCSkewBy
CCActionInterval *skewBy=CCSkewBy::create(2, 10, 10);
CCActionInterval *actionByBack=skewBy->reverse();
sp->runAction(actionByBack);
}
break;
case 7:
{
//-------------CCJumpTo
CCActionInterval *jumpTo=CCJumpTo::create(2, ccp(300, 200), 50, 4);
sp->runAction(jumpTo);
}
break;
case 8:
{
//-------------CCJumpBy
CCActionInterval *jumpBy=CCJumpBy::create(2, ccp(300, 200), 50, 4);
CCActionInterval *actionByBack=jumpBy->reverse();
sp->runAction(actionByBack);
}
break;
case 9:
{
//-------------CCBezier
ccBezierConfig bezierCon;
bezierCon.controlPoint_1=CCPointMake(200, 150);
bezierCon.controlPoint_2=CCPointMake(200, 260);
bezierCon.endPosition=CCPointMake(340, 100);
//-------------CCBezierTo
CCActionInterval *bezierTo=CCBezierTo::create(2, bezierCon);
sp->runAction(bezierTo);
}
break;
case 10:
{
//-------------CCBezier
ccBezierConfig bezierCon;
bezierCon.controlPoint_1=CCPointMake(200, 150);
bezierCon.controlPoint_2=CCPointMake(200, 260);
bezierCon.endPosition=CCPointMake(340, 100);
//-------------CCBezierBy
CCActionInterval *bezierBy=CCBezierTo::create(2, bezierCon);
CCActionInterval *actionByBack=bezierBy->reverse();
sp->runAction(actionByBack);
}
break;
case 11:
{
//--------------FadeIn
CCActionInterval *fadeIn=CCFadeIn::create(2);
sp->runAction(fadeIn);
}
break;
case 12:
{
//---------------FadeOut
CCActionInterval *fadeOut=CCFadeOut::create(2);
sp->runAction(fadeOut);
}
break;
case 13:
{
//---------------CCTintTo
CCActionInterval *tiniTo=CCTintTo::create(2, 255, 0, 0);
sp->runAction(tiniTo);
}
break;
case 14:
{
//---------------CCTintBy
CCActionInterval *tiniBy=CCTintBy::create(2, 255, 0, 0);
CCActionInterval *actionByBack=tiniBy->reverse();
sp->runAction(actionByBack);
}
break;
case 15:
{
//---------------CCBlink
CCActionInterval *blink=CCBlink::create(10, 3);
sp->runAction(blink);
}
break;
case 16:
{
//---------------CCDelayTime
CCActionInterval *delayTime=CCDelayTime::create(2);
sp->runAction(delayTime);
}
break;
case 17:
{
//---------------CCOrbitCamera
CCActionInterval *orbitCamera=CCOrbitCamera::create(3, 1, 0, 45, 100, 90, 0);
sp->runAction(orbitCamera);
}
break;
case 18:
{
//----------------CCCardinalSpline
CCPointArray *array=CCPointArray::create(20);
array->addControlPoint(ccp(0,0));
array->addControlPoint(ccp(210,0));
array->addControlPoint(ccp(210,240));
array->addControlPoint(ccp(0,160));
array->addControlPoint(ccp(0,0));
//--------CCCardinalSplineTo
CCActionInterval *splineTo=CCCardinalSplineTo::create(4, array, 0);
sp->runAction(splineTo);
}
break;
case 19:
{
//----------------CCCardinalSpline
CCPointArray *array=CCPointArray::create(20);
array->addControlPoint(ccp(0,0));
array->addControlPoint(ccp(210,0));
array->addControlPoint(ccp(210,240));
array->addControlPoint(ccp(0,160));
array->addControlPoint(ccp(0,0));
//--------CCCardinalSplineBy
CCActionInterval *splineBy=CCCardinalSplineBy::create(4, array, 0);
CCActionInterval *actionByBack=splineBy->reverse();
sp->runAction(actionByBack);
}
break;
case 20:
{
//----------CCCatmullRom
CCPointArray *array=CCPointArray::create(20);
array->addControlPoint(ccp(240,30));
array->addControlPoint(ccp(400,30));
array->addControlPoint(ccp(400,240));
array->addControlPoint(ccp(240,240));
array->addControlPoint(ccp(240,30));
//---CCCatmullRomTo
CCCatmullRomTo *romTo=CCCatmullRomTo::create(2, array);
sp->runAction(romTo);
}
break;
case 21:
{
//----------CCCatmullRom
CCPointArray *array=CCPointArray::create(20);
array->addControlPoint(ccp(240,30));
array->addControlPoint(ccp(400,30));
array->addControlPoint(ccp(400,240));
array->addControlPoint(ccp(240,240));
array->addControlPoint(ccp(240,30));
//---CCCatmullRomTo
CCCatmullRomBy *romBy=CCCatmullRomBy::create(2, array);
CCActionInterval *actionByBack=romBy->reverse();
sp->runAction(actionByBack);
}
break;
case 22:
{
//-------------CCFollow
//创建一个参照物spT
CCSprite *spT=CCSprite::create("Icon.png");
spT->setPosition(ccp(420,40));
addChild(spT);
sp->runAction(CCMoveTo::create(3, ccp(940,sp->getPositionY())));
CCFollow *follow=CCFollow::create(sp,CCRectMake(0, 0, 960, 320));
this->runAction(follow);
}
break;
case 23:
{
//-------------CCEaseBounce
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//----------CCEaseBounceIn
CCActionInterval *easeBounceIn=CCEaseBounceIn::create(move);
sp->runAction(easeBounceIn);
}
break;
case 24:
{
//-------------CCEaseBounce
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//----------CCEaseBounceOut
CCActionInterval *easeBounceOut=CCEaseBounceOut::create(move);
sp->runAction(easeBounceOut);
}
break;
case 25:
{
//-------------CCEaseBounce
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//----------CCEaseBounceInOut
CCActionInterval *easeBounceInOut=CCEaseBounceInOut::create(move);
sp->runAction(easeBounceInOut);
}
break;
case 26:
{
//---------CCEaseBack
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//-----CCEaseBackIn
CCActionInterval *easeBackIn=CCEaseBackIn::create(move);
sp->runAction(easeBackIn);
}
break;
case 27:
{
//---------CCEaseBack
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//-----CCEaseBackIn
CCActionInterval *easeBackOut=CCEaseBackOut::create(move);
sp->runAction(easeBackOut);
}
break;
case 28:
{
//---------CCEaseBack
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//-----CCEaseBackInOut
CCActionInterval *easeBackInOut=CCEaseBackInOut::create(move);
sp->runAction(easeBackInOut);
}
break;
case 29:
{
//---------CCEaseElastic
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseElasticIn
CCActionInterval *easeElasticIn=CCEaseElasticIn::create(move);
sp->runAction(easeElasticIn);
}
break;
case 30:
{
//---------CCEaseElastic
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseElasticOut
CCActionInterval *easeElasticOut=CCEaseElasticOut::create(move);
sp->runAction(easeElasticOut);
}
break;
case 31:
{
//---------CCEaseElastic
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseElasticInOut
CCActionInterval *easeElasticInOut=CCEaseElasticInOut::create(move);
sp->runAction(easeElasticInOut);
}
break;
case 33:
{
//---------CCEaseExponential
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseExponential
CCActionInterval *exponentialIn=CCEaseExponentialIn::create(move);
sp->runAction(exponentialIn);
}
break;
case 34:
{
//---------CCEaseExponential
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseExponential
CCActionInterval *exponentialOut=CCEaseExponentialOut::create(move);
sp->runAction(exponentialOut);
}
break;
case 35:
{
//---------CCEaseExponential
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseExponential
CCActionInterval *exponentialInOut=CCEaseExponentialInOut::create(move);
sp->runAction(exponentialInOut);
}
break;
case 36:
{
//---------CCEaseRateAction
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
CCActionInterval *easeRateAction=CCEaseRateAction::create(move,0.5);
sp->runAction(easeRateAction);
}
break;
case 37:
{
//---------CCEaseSine
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseSineIn
CCActionInterval *easeSineIn=CCEaseSineIn::create(move);
sp->runAction(easeSineIn);
}
break;
case 38:
{
//---------CCEaseSine
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseSineOut
CCActionInterval *easeSineOut=CCEaseSineOut::create(move);
sp->runAction(easeSineOut);
}
break;
case 39:
{
//---------CCEaseSine
CCActionInterval *move=CCMoveTo::create(5, ccp(300,sp->getPositionY()));
//---------CCEaseSineInOut
CCActionInterval *easeSineInOut=CCEaseSineInOut::create(move);
sp->runAction(easeSineInOut);
}
break;
case 40:
{
//--------CCSpeed
CCActionInterval *move=CCMoveTo::create(10, ccp(300, sp->getPositionY()));
CCSpeed *speed=CCSpeed::create(move, 10);
sp->runAction(speed);
}
break;
case 41:
{
//--------CCSpawn
CCActionInterval *move=CCMoveTo::create(5, ccp(300, sp->getPositionY()));
CCActionInterval *scale=CCScaleTo::create(2,3);
CCActionInterval *rotate=CCRotateTo::create(4,190);
CCFiniteTimeAction *spwn=CCSpawn::create(move,scale,rotate,NULL);
sp->runAction(spwn);
}
break;
case 42:
{
//--------CCSequence
CCActionInterval *move=CCMoveTo::create(2, ccp(300, sp->getPositionY()));
CCActionInterval *scale=CCScaleTo::create(2,3);
CCFiniteTimeAction *seq=CCSequence::create(move,scale,NULL);
sp->runAction(seq);
}
break;
case 43:
{
//-------Reverse CCSequence
CCActionInterval *move=CCMoveBy::create(2, ccp(300, sp->getPositionY()));
CCActionInterval *scale=CCScaleBy::create(2,3);
CCFiniteTimeAction *seq=CCSequence::create(move,scale,NULL);
CCFiniteTimeAction *reverseSeq=CCSequence::create(seq,seq->reverse(),NULL);
sp->runAction(reverseSeq);
}
break;
case 44:
{
//--------CCRepeat
CCActionInterval *move=CCMoveTo::create(2, ccp(300, sp->getPositionY()));
CCActionInterval *move2=CCMoveTo::create(2, ccp(100, 100));
CCFiniteTimeAction *seq=CCSequence::create(move,move2,NULL);
CCActionInterval *repeat=CCRepeat::create(seq, 2);
sp->runAction(repeat);
}
break;
case 45:
{
//-------CCRepeatForever
CCActionInterval *move=CCMoveTo::create(2, ccp(300, sp->getPositionY()));
CCActionInterval *move2=CCMoveTo::create(2, ccp(100, 100));
CCFiniteTimeAction *seq=CCSequence::create(move,move2,NULL);
CCActionInterval *repeatForever=CCRepeatForever::create((CCActionInterval*)seq);
sp->runAction(repeatForever);
}
break;
case 46:
{
//-------CCCallFunc
CCActionInterval *move=CCMoveTo::create(1, ccp(300, sp->getPositionY()));
CCCallFunc *funCall=CCCallFunc::create(this, callfunc_selector(HelloWorld::callbackC));
CCFiniteTimeAction *seq=CCSequence::create(move,funCall,NULL);
sp->runAction(seq);
}
break;
case 47:
{
//-------CCCallFuncN
CCActionInterval *move=CCMoveTo::create(1, ccp(300, sp->getPositionY()));
CCCallFunc *funCall=CCCallFuncN::create(this, callfuncN_selector(HelloWorld::callbackN));
CCFiniteTimeAction *seq=CCSequence::create(move,funCall,NULL);
sp->runAction(seq);
}
break;
case 48:
{
//-------CCCallFuncND
CCActionInterval *move=CCMoveTo::create(1, ccp(300, sp->getPositionY()));
CCCallFunc *funCall=CCCallFuncND::create(this, callfuncND_selector(HelloWorld::callbackND),NULL);
CCFiniteTimeAction *seq=CCSequence::create(move,funCall,NULL);
sp->runAction(seq);
}
break;
}
return true;
}
void HelloWorld::callbackC()
{
CCLOG("callbackC");
}
void HelloWorld::callbackN(CCNode* sender)
{
CCLOG("callbackN");
}
void HelloWorld::callbackND(CCNode* sender,void* data)
{
CCLOG("callbackND");
}