前端之家收集整理的这篇文章主要介绍了
cocos2dx 常见的49中动作,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- boolHelloWorld::init()
- {
-
-
- if(!CCLayer::init())
- returnfalse;
- }
-
- CCSprite*sp=CCSprite::create("Icon.png");
- sp->setPosition(ccp(150,150));
- addChild(sp,922);
- ////Action动作
- //
- ////CCMoveBy创建一个移动的动作参数1:移动到目标坐标所需的时间参数2:目标坐标支持reverse可以获取其反向动作
- ////CCMoveTo一样的
- //CCActionInterval*moveBy=CCMoveBy::create(5,ccp(300,100));
- //CCActionInterval*actionmoveback=moveBy->reverse();
- //sp->runAction(actionmoveback);
- ////CCScaleTo作用:创建一个缩放的动作
- ////参数1:达到缩放大小所需的时间
- ////参数2:缩放的比例
- //CCActionInterval*scaleto=CCScaleTo::create(2,2);
- //sp->runAction(scaleto);
- ////CCScaleBy作用:创建一个缩放的动作
- ////参数1:达到缩放大小的所需时间参数2:缩放比例
- //CCActionInterval*scaleby=CCScaleBy::create(2,2);
- //CCActionInterval*actionbyback=scaleby->reverse();
- //sp->runAction(actionbyback);
- ////CCRotateTo
- ////作用创建一个旋转的动作
- ////参数1:旋转的时间参数2:旋转饿角度0-360
- //CCActionInterval*rotateto=CCRotateTo::create(2,90);
- //sp->runAction(rotateto);
- ////CCSkewTo
- ////作用创建一个倾斜的动作
- ////参数1:倾斜到特定角度所需的时间
- ////参数2:x轴的倾斜角度
- ////参数3:y轴的倾斜角度
- //CCActionInterval*skewto=CCSkewTo::create(2,10,10);
- //sp->runAction(skewto);
- ////CCJumpTo
- ////作用:创建一个跳的动作
- ////参数1:跳到目标动作位子的所需时间
- ////参数2:目标位置
- ////参数3:跳的高度
- ////参数4跳到目标位置的次数
- //CCActionInterval*jumpto=CCJumpTo::create(2,200),50,4);
- //sp->runAction(jumpto);
- //
- ////CCJumpBy
- ////作用:创建一个跳的动作
- ////参数1:跳到目标动作位子的所需时间
- ////参数2:目标位置
- ////参数3:跳的高度
- ////参数4跳到目标位置的次数
- ////这个支持方向动作reverse
- //CCActionInterval*jumpby=CCJumpBy::create(3,0); background-color:inherit">//CCActionInterval*ac=jumpby->reverse();
- //sp->runAction(ac);
- //CCBezier
- //ccBezierConfig结构体
- //ccBezierConfigbezierCon;
- //bezierCon.controlPoint_1=CCPointMake(200,150);//控制点1
- //bezierCon.controlPoint_2=CCPointMake(200,160);//控制点2
- //bezierCon.endPosition=CCPointMake(340,100);//结束位置
- //CCBezierTo
- //创建一个贝塞尔曲线运动的动作
- //参数1:贝塞尔曲线运动的时间
- //参数2:ccBezierConfig结构体
- //CCActionInterval*action=CCBezierTo::create(2,bezierCon);
- //CCActionInterval*action=CCBezierBy::create(3,bezierCon);//支持反向
- //CCActionInterval*action1=action->reverse();
- //sp->runAction(action1);
-
- //CCFadeIn
- //作用:创建一个渐变出现的动作
- //参数是时间
- //CCActionInterval*fadein=CCFadeIn::create(2);
- //sp->runAction(fadein);
- //CCFadeOut
- //作用:创建一个渐变消失的动作
- //CCActionInterval*fadeout=CCFadeOut::create(2);
- //sp->runAction(fadeout);
- //CCTintTo
- //作用:创建一个色彩变化的消失动作
- //参数1:色彩变化的动作
- //参数2:红色分量
- //参数3:蓝色分量
- //CCActionInterval*tinto=CCTintTo::create(3,255,0);
- //sp->runAction(tinto);
- //CCTintBy
- //作用:创建一个色彩变化的出现动作
- //参数1:色彩变化的动作
- //参数2:红色分量
- //参数3:蓝色分量但是家了reverse就是反向的
- //CCActionInterval*tintby=CCTintBy::create(3,255);
- //CCActionInterval*tintby1=tintby->reverse();
- //sp->runAction(tintby1);
- //CCBlink
- //作用:创建一额闪烁的动作
- //参数1:闪烁完成的时间
- //参数2:闪烁的次数
- //CCActionInterval*blink=CCBlink::create(3,10);
- //sp->runAction(blink);
- //CCDelayTime
- //创建一个延迟的动作
- //参数延迟的时间
- //CCActionInterval*delaytime=CCDelayTime::create(3);
- //sp->runAction(delaytime);
- //CCOrbitCamera
- //作用:创建一个球面坐标轨迹进行旋转的动作
- //参数1:旋转轨迹的时间
- //参数2:起始半径
- //参数3:半径差
- //参数4:起始z角
- //参数5:旋转z角的差
- //参数6:起始x角
- //参数7:旋转x角的差
- //CCActionInterval*orbitcamera=CCOrbitCamera::create(3,45,180,90,0);
- //sp->runAction(orbitcamera);
- //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));
- //CCCardinalSplineTo
- //作用:创建一个样条曲线轨迹的动作
- //参数1:完成轨迹所需的时间
- //参数2:控制点的坐标数组
- //拟合度其值=0路径最柔和
- //CCActionInterval*CardinalSplineTo=CCCardinalSplineTo::create(3,array,0); background-color:inherit">//sp->runAction(CardinalSplineTo);
- //CCCardinalSplineBy
- //作用:创建一个样条曲线轨迹的动作
- //参数1:完成轨迹所需的时间
- //参数2:控制点的坐标数组
- //拟合度其值=0路径最柔和
- //CCActionInterval*CardinalSplineBy=CCCardinalSplineBy::create(3,0); background-color:inherit">//sp->runAction(CardinalSplineBy);
- //CCCatmullRomToCCCatmullRomBY
- //作用:创建一个样条插值轨迹
- //参数1:完成轨迹的时间
- //参数2:控制点的数组坐标
- //CCActionInterval*catmullRomTo=CCCatmullRomTo::create(3,array);
- //sp->runAction(catmullRomTo);
- //CCFollow
- //作用:创建一个跟随动作
- //参数1:跟随的目标对象
- //跟随范围,离开范围就不再跟随
- //创建一个参照物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,960,320));
- //this->runAction(follow);
- //CCEaseBounceIn
- //目标动作
- //CCActionInterval*move=CCMoveTo::create(3,sp->getPositionY()));
- ////让目标动作缓慢开始
- ////参数:目标动作
- //CCActionInterval*EaseBounceIn=CCEaseBounceIn::create(move);
- //sp->runAction(EaseBounceIn);
- //CCEaseBounceOut
- //作用:让目标动作赋予反弹力,且以目标动作结束位子开始反弹
- //参数目标动作
- //CCActionInterval*easeBounceOut=CCEaseBounceOut::create(move);
- //sp->runAction(easeBounceOut);
- //CCEaseBounceInOut
- //作用:让目标动作赋予反弹力,且以目标动作起始与结束位子开始反弹
- //CCActionInterval*easeBounceInOut=CCEaseBounceInOut::create(move);
- //sp->runAction(easeBounceInOut);
- //CCEaseBackIn
- //作用:让目标动作赋予回力,且以目标动作起点位置作为回力点
- //参数:目标动作
- //CCActionInterval*easeBackIn=CCEaseBackIn::create(move);
- //sp->runAction(easeBackIn);
- //CCEaseBackOut
- //作用:让目标动作赋予回力,且以目标动作终点位置作为回力点
- //CCActionInterval*easeBackOut=CCEaseBackOut::create(move);
- //sp->runAction(easeBackOut);
- //CCEaseBackInOut
- //作用:让目标动作赋予回力,且以目标动作起点和终点位置作为回力点
- //CCActionInterval*easeBackInOut=CCEaseBackInOut::create(move);
- //sp->runAction(easeBackInOut);
- //CCEaseElasticIn
- //作用:让目标动作赋予弹性,且以目标动作起点位子赋予弹性
- //CCActionInterval*easeElasticIn=CCEaseElasticIn::create(move);
- //sp->runAction(easeElasticIn);
- //CCEaseElasticOut
- //作用:让目标动作赋予弹性,且以目标动作终点位子赋予弹性
- //CCActionInterval*easeElasticOut=CCEaseElasticOut::create(move);
- //sp->runAction(easeElasticOut);
- //CCEaseElasticInOut
- //作用:让目标动作赋予弹性,且以目标动作起点和终点位子赋予弹性
- //CCActionInterval*easeElasticInOut=CCEaseElasticOut::create(move);
- //sp->runAction(easeElasticInOut);
- //CCEaseExponentialIn
- //让目标动作缓慢开始
- //CCActionInterval*easeExponentialIn=CCEaseExponentialIn::create(move);
- //sp->runAction(easeExponentialIn);
- //CCEaseExponentialOut
- //让目标动作缓慢中止
- //CCActionInterval*easeExponentialIn=CCEaseExponentialOut::create(move);
- //CCEaseExponentialInOut
- //让目标动作缓慢开始和中止
- //CCActionInterval*easeExponentialInOut=CCEaseExponentialInOut::create(move);
- //sp->runAction(easeExponentialInOut);
- //CCEaseRateAction
- //作用:让目标动作设置速率
- //参数1:目标动作
- //参数2:速率
- //CCActionInterval*move=CCMoveTo::create(5,sp->getPositionY()));
- //CCActionInterval*easeRateAction=CCEaseRateAction::create(move,3);
- //sp->runAction(easeRateAction);
- //CCEaseSineIn
- //作用:动作由慢到快
- //CCActionInterval*easeSineIn=CCEaseSineIn::create(move);
- //sp->runAction(easeSineIn);
- //CCEaseSineOut
- //作用:动作由快到慢
- //CCActionInterval*easeSineOut=CCEaseSineOut::create(move);
- //sp->runAction(easeSineOut);
- //CCEaseSineInOut
- //作用:动作由慢到快再快到慢
- //CCActionInterval*easeSineInOut=CCEaseSineInOut::create(move);
- //sp->runAction(easeSineInOut);
- //CCSpeed
- //作用:让目标动作运行速度加倍
- //参数1:目标动作
- //参数2:倍速
- //CCActionInterval*move=CCMoveTo::create(10,0); background-color:inherit">//CCSpeed*speed=CCSpeed::create(move,100);
- //sp->runAction(speed);
- //CCSpawn
- //作用:让多个动作同时执行
- //参数:目标动作的可变参数
- //CCActionInterval*scale=CCScaleTo::create(2,3);
- //CCActionInterval*rotate=CCRotateTo::create(4,190);
- //CCFiniteTimeAction*spawn=CCSpawn::create(move,scale,rotate,NULL);
- //sp->runAction(spawn);
- //CCSequence
- //作用:让多个动作按照前后顺序逐一执行
- //参数:目标动作的可变参数
- //CCActionInterval*move=CCMoveTo::create(2,0); background-color:inherit">//CCFiniteTimeAction*seq=CCSequence::create(move,0); background-color:inherit">//sp->runAction(seq);
- //扩展如果要对目标动作全部进行方向运动,可以使用如下形式操作
- //CCFiniteTimeAction*seq=CCSequence::create(moveby,scaleby,...NULL);
- //CCFiniteTimeAction*reverseseq=CCSequence::create(seq,seq->reverse(),NULL)
- //注意CCSequence中的所有动作都必须支持reverse函数,否则会出现异常
- //CCActionInterval*move=CCMoveBy::create(2,0); background-color:inherit">//CCActionInterval*scale=CCScaleBy::create(2,0); background-color:inherit">//CCFiniteTimeAction*reveseseq=CCSequence::create(seq,NULL);
- //sp->runAction(reveseseq);
- //CCRepeat
- //作用:对目标动作进行重复运动(目标动作可以是CCSequence,CCSpawn)
- //参数2:重复次数
- //CCActionInterval*move2=CCMoveTo::create(2,ccp(100,100));
- //CCFiniteTimeAction*repeat=CCRepeat::create(seq,0); background-color:inherit">//sp->runAction(repeat);
- //CCRepeatForever
- //作用:对目标动作进行永久性的重复运动(目标动作可以是CCSequence,CCSpawn)
- //CCActionInterval*move=CCMoveTo::create(1,0); background-color:inherit">//CCActionInterval*move1=CCMoveTo::create(1,move1,0); background-color:inherit">//CCActionInterval*repeatForever=CCRepeatForever::create((CCActionInterval*)seq);
- //sp->runAction(repeatForever);
- //CCCallFunc
- //作用:创建一个回调动作(调用不带参数的回调方法);
- //参数1:目标动作
- //参数2:目标回调函数
- //CCCallFunc*funcall=CCCallFunc::create(this,callfunc_selector(HelloWorld::callbackC));
- //sp->runAction(seq);
- //CCCallFuncN
- //作用:创建一个回调动作(调用带一个参数的回调方法);
- //参数2:目标回调函数
- //CCCallFuncN*funcall=CCCallFuncN::create(this,callfuncN_selector(HelloWorld::callbackN));
- //CCCallFuncND
- //作用:创建一个回调动作(调用带两个参数的回调方法);
- CCActionInterval*move=CCMoveTo::create(1,sp->getPositionY()));
- CCCallFuncND*funcall=CCCallFuncND::create(this,callfuncND_selector(HelloWorld::callbackND),(void*)0xbebabeba);
- CCFiniteTimeAction*seq=CCSequence::create(move,NULL);
- sp->runAction(seq);
- true;
- voidHelloWorld::callbackC()
- CCLOG("callbackC");
- voidHelloWorld::callbackN(CCNode*sender)
- {
- CCLOG("callbackN");
- }
- voidHelloWorld::callbackND(CCNode*sender,void*data)
- CCLOG("callbackND");
- }
原文链接:https://www.f2er.com/cocos2dx/340520.html