cocos2dx 常见的49中动作详解及常用函数

stopAllActions();//终止所有动作。

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);
 
    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, ccp(300, 200), 50, 4 );
//    sp->runAction(jumpto);
//   
    CCJumpBy
//    //    作用:创建一个跳的动作
//    //    参数1:跳到目标动作位子的所需时间
//    //    参数2:目标位置
//    //    参数3:跳的高度
//    //    参数4跳到目标位置的次数
    这个支持方向动作reverse
//    CCActionInterval * jumpby = CCJumpBy ::create(3, ccp(300, 200), 50, 4);
//       CCActionInterval * ac= jumpby->reverse();
//    sp->runAction(ac);
   
//    CCBezier
//ccBezierConfig结构体   
//    ccBezierConfig bezierCon;
//    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, 255, 0);
//    sp->runAction(tinto);
 
   
//    CCTintBy
    //    作用:创建一个色彩变化的出现动作
    //    参数1:色彩变化的动作
    //    参数2 :红色分量
    //    参数3:蓝色分量   但是家了reverse就是 反向的
//    CCActionInterval * tintby = CCTintBy::create(3, 0, 255, 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, 10, 0, 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));
    array->addControlPoint(ccp(0,0));
//    CCCardinalSplineTo
//    作用:创建一个样条曲线轨迹的动作
//    参数1:完成轨迹所需的时间
//    参数2:控制点的坐标数组
//    拟合度  其值= 0 路径最柔和
//    CCActionInterval  * CardinalSplineTo=CCCardinalSplineTo::create(3, array, 0);
//   sp->runAction(CardinalSplineTo);
//CCCardinalSplineBy
    //    作用:创建一个样条曲线轨迹的动作
    //    参数1:完成轨迹所需的时间
    //    参数2:控制点的坐标数组
    //    拟合度  其值= 0 路径最柔和
//    CCActionInterval * CardinalSplineBy = CCCardinalSplineBy::create(3, array, 0);
//    sp->runAction(CardinalSplineBy);
   
//    CCCatmullRomTo  CCCatmullRomBY
//    作用:创建一个样条插值轨迹
//    参数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, 0, 960, 320));
//    this-> runAction(follow);
   
//    CCEaseBounceIn
//    目标动作
//    CCActionInterval* move = CCMoveTo::create(3, ccp(300, 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);
//    sp->runAction(easeExponentialIn);
   
//    CCEaseExponentialInOut
    //    让目标动作缓慢开始和中止
    //    参数:目标动作
//    CCActionInterval * easeExponentialInOut= CCEaseExponentialInOut::create(move);
//    sp->runAction(easeExponentialInOut);
   
//    CCEaseRateAction
//    作用 : 让目标动作设置速率
//    参数1:目标动作
//    参数2:速率
//    CCActionInterval * move = CCMoveTo::create(5, ccp(300,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, ccp(300,sp->getPositionY()));
//    CCSpeed * speed =CCSpeed::create(move, 100);
//    sp->runAction(speed);
   
//    CCSpawn
//  作用:让多个动作同时执行
//    参数:目标动作的可变参数
//    CCActionInterval * move = CCMoveTo::create(10, ccp(300,sp->getPositionY()));
//    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, ccp(300, sp->getPositionY()));
//    CCActionInterval * scale = CCScaleTo::create(2, 3);
//    CCFiniteTimeAction * seq= CCSequence::create(move,scale,NULL);
//    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, ccp(300, sp->getPositionY()));
//    CCActionInterval * scale = CCScaleBy::create(2, 3);
//    CCFiniteTimeAction * seq= CCSequence::create(move,scale,NULL);
//    CCFiniteTimeAction * reveseseq = CCSequence::create(seq,seq->reverse(),NULL);
//    sp->runAction(reveseseq);
   
//    CCRepeat
//    作用:对目标动作进行重复运动(目标动作可以是CCSequence ,CCSpawn)
//    参数1:目标动作
//    参数2:重复次数
//    CCActionInterval * move = CCMoveTo::create(2, ccp(300, sp->getPositionY()));
//    CCActionInterval * move2 = CCMoveTo::create(2, ccp(100,100));
//    CCFiniteTimeAction*seq =CCSequence::create(move,move2,NULL);
//    CCFiniteTimeAction *repeat = CCRepeat::create(seq, 3);
//    sp->runAction(repeat);
   
//    CCRepeatForever
//    作用:对目标动作进行永久性的重复运动(目标动作可以是CCSequence ,CCSpawn)
//    参数:目标动作
//    CCActionInterval * move = CCMoveTo::create(1, ccp(300, sp->getPositionY()));
//    CCActionInterval * move1 = CCMoveTo::create(1, ccp(100,100));
//    CCFiniteTimeAction* seq = CCSequence::create(move,move1,NULL);
//    CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
//    sp->runAction(repeatForever);
   
//    CCCallFunc
//    作用:创建一个回调动作(调用不带参数的回调方法);
//    参数1:目标动作
//    参数2:目标回调函数
//    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);
   
//    CCCallFuncN
    //    作用:创建一个回调动作(调用 带一个参数的回调方法);
    //    参数1:目标动作
    //    参数2:目标回调函数
//    CCActionInterval * move = CCMoveTo::create(1, ccp(300, sp->getPositionY()));
//    CCCallFuncN * funcall= CCCallFuncN::create(this, callfuncN_selector(HelloWorld::callbackN));
//    CCFiniteTimeAction * seq = CCSequence::create(move,funcall,NULL);
//    sp->runAction(seq);
   
//    CCCallFuncND
    //    作用:创建一个回调动作(调用 带两个参数的回调方法);
    //    参数1:目标动作
    //    参数2:目标回调函数
    CCActionInterval * move = CCMoveTo::create(1, ccp(300, sp->getPositionY()));
    CCCallFuncND * funcall= CCCallFuncND::create(this, callfuncND_selector(HelloWorld::callbackND)  ,(void*)0xbebabeba);
    CCFiniteTimeAction * seq = CCSequence::create(move,funcall,NULL);
    sp->runAction(seq);
    return true;
}
void HelloWorld::callbackC()
{
    CCLOG("callbackC");
}

void HelloWorld::callbackN(CCNode* sender)
{
    CCLOG("callbackN");
}

void HelloWorld::callbackND(CCNode* sender, void* data)
{
    CCLOG("callbackND");
}

——————————————————————————————————————————————————————————————————————————————

延时动作就是指动作的完成需要一段时间。因此,几乎所有的延时动作都使用执行时间作为第一个参数,它们有着共同的基类CCActionInterval
cocos2d-x中常用的延时动作:
这里有一个简单的类命名规则:
CCXxxxTo – 绝对动作,执行的结果与当前的状态关系不密切;
CCXxxxBy – 相对动作,在当前的状态上执行某种动作,执行的结果与当前状态是紧密相关的。
移动到 – CCMoveTo
移动 – CCMoveBy
跳跃到 – CCJumpTo
参数为终点位置、跳跃高度和跳跃次数。
跳跃 – CCJumpBy
贝赛尔曲线 – CCBezierBy
支持三次贝赛尔曲线:P0-起点,P1-起点切线方向,P2-终点切线方向,P3-终点。

首先设置贝塞尔参数,然后执行。
放大到 – CCScaleTo
放大 – CCScaleBy
如果参数为小数,那就是缩小了。
旋转到 – CCRotateTo
旋转 – CCRotateBy
闪烁 – CCBlink
色调变化到 – CCTintTo
色调变换 – CCTintBy
变暗到 – CCFadeTo
由无变亮 – CCFadeIn
由亮变无 – CCFadeOut

组合动作

按照一定的次序将上述基本动作组合起来,形成连贯的一套组合动作。组合动作包括以下几类:
 

序列 – CCSequence

序列的使用非常简单,该类从CCActionInterval派生,本身就可以被CCNode对象执行。该类的作用就是线性排列若干个动作,然后按先后次序逐个执行。
  
  
  1. void CompositionActionLayer::onSequence(CCObject* pSender)
  2. {
  3. CCSize s = CCDirector::sharedDirector()->getWinSize();
  4. // 创建5个动作
  5. CCFiniteTimeAction *action0 = CCPlace::actionWithPosition(ccp(s.width / 2, 50));
  6. CCFiniteTimeAction *action1 = CCMoveTo::actionWithDuration(1.2f, ccp(s.width - 50.0f, s.height - 50.0f));
  7. CCFiniteTimeAction *action2 = CCJumpTo::actionWithDuration(1.2f, ccp(150, 50), 30.0f, 5);
  8. CCFiniteTimeAction *action3 = CCBlink::actionWithDuration(1.2f, 3);
  9. CCFiniteTimeAction *action4 = CCTintBy::actionWithDuration(0.5f, 0, 255, 255);
  10. // 将5个动作组合为一个序列,注意不要忘了用NULL结尾。
  11. flight->runAction(CCSequence::actions(action0, action1, action2, action3, action4, action0, NULL));
  12. }

同步 – CCSpawn

同步的使用非常简单,该类也是从CCActionInterval派生,可以被CCNode对象执行。该类的作用就是同时并列执行若干个动作,但要求动作本身是可以同时执行的,比如:移动式翻转、变色、缩放等。
需要特别注意的是,同步执行最后完成的时间由基本动作中用时最大者决定。
  
  
  1. void CompositionActionLayer::onSpawn(CCObject* pSender)
  2. {
  3. CCSize s = CCDirector::sharedDirector()->getWinSize();
  4. flight->setRotation(0.0f);
  5. flight->setPosition(ccp(s.width / 2, 50));
  6. // 创建4个需要并行的动作,确保动作用时可组合。(action1/action2/sequence的执行时间都是2秒)
  7. CCFiniteTimeAction *action1 = CCMoveTo::actionWithDuration(2.0f, ccp(s.width - 50.0f, s.height - 50.0f));
  8. CCFiniteTimeAction *action2 = CCRotateTo::actionWithDuration(2.0f, 180.0f);
  9. CCFiniteTimeAction *action3 = CCScaleTo::actionWithDuration(1.0f, 4.0f);
  10. CCFiniteTimeAction *action4 = CCScaleBy::actionWithDuration(1.0f, 0.5f);
  11. CCFiniteTimeAction *sequence = CCSequence::actions(action3, action4, NULL);
  12. // 创建并执行同步动作。
  13. flight->runAction(CCSpawn::actions(action1, action2, sequence, NULL));
  14. }

重复有限次数 – CCRepeat

CCRepeat用来将某一动作重复有限次数,示例代码如下:
  
  
  1. void CompositionActionLayer::onRepeat(CCObject* pSender)
  2. {
  3. CCSize s = CCDirector::sharedDirector()->getWinSize();
  4. flight->setRotation(0.0f);
  5. flight->setPosition(ccp(s.width / 2, 50));
  6. // 创建动作序列
  7. CCFiniteTimeAction *action1 = CCMoveTo::actionWithDuration(2.0f, ccp(s.width - 50.0f, s.height - 50.0f));
  8. CCFiniteTimeAction *action2 = CCJumpBy::actionWithDuration(2.0f, ccp(-400, -200), 30.0f, 5);
  9. CCFiniteTimeAction *action3 = CCJumpBy::actionWithDuration(2.0f, ccp(s.width / 2, 0), 20.0f, 3);
  10. CCFiniteTimeAction *sequence = CCSequence::actions(action1, action2, action3, NULL);
  11. // 重复运行上述动作序列3次
  12. flight->runAction(CCRepeat::actionWithAction(sequence, 3));
  13. }

反动作 – Reverse

反动作就是反向(逆向)执行某个动作,支持针对动作序列的反动作序列。反动作不是一个专门的类,而是CCFiniteTimeAction引入的一个接口。不是所有的类都支持反动作,CCXxxxTo类通常不支持反动作,而CCXxxxBy类通常支持,示例如下:
  
  
  1. void CompositionActionLayer::onReverse(CCObject* pSender)
  2. {
  3. CCSize s = CCDirector::sharedDirector()->getWinSize();
  4. flight->setRotation(0.0f);
  5. flight->setPosition(ccp(s.width / 2, 50));
  6.  
  7. CCFiniteTimeAction *action1 = CCMoveBy::actionWithDuration(2.0f, ccp(190, 220));
  8. // 创建某个动作的反动作
  9. CCFiniteTimeAction *action2 = action1->reverse();
  10.  
  11. flight->runAction(CCRepeat::actionWithAction(CCSequence::actions(action1, action2, NULL), 2));
  12. }

动画 – CCAnimate

动画就是让精灵自身连续执行一段影像,形成模拟运动的效果:行走时的状态,打斗时的状态等。
  
  
  1. void CompositionActionLayer::onAnimation(CCObject* pSender)
  2. {
  3. CCSpriteBatchNode *mgr = static_cast(this->getChildByTag(4));
  4.  
  5. CCAnimation *animation = CCAnimation::animation();
  6. animation->setName("flight");
  7. animation->setDelay(0.2f);
  8. for (int i = 0; i < 3; ++i)
  9. {
  10. // 定义每一帧的内容
  11. float x = static_cast(i % 3);
  12. animation->addFrameWithTexture(mgr->getTexture(), CCRectMake(x * 32, 0, 31, 30));
  13. }
  14. // 创建并执行动画效果,而且要重复10次。
  15. CCAnimate *action = CCAnimate::actionWithAnimation(animation);
  16. flight->runAction(CCRepeat::actionWithAction(action, 10));
  17. }

无限重复 – CCRepeatForever

CCRepeatForever Class Reference中,有这样一条警告“Warning: This action can’t be Sequenceable because it is not an IntervalAction”,而实际上它的确是派生自CCActionInterval,这真有点儿把我也搞懵了。
仅从其本意来说,该类的作用就是无限期执行某个动作或动作序列,直到被停止。因此无法参与序列和同步,自身也无法反向执行(但是你可以将某一动作反向,然后无限重复执行)。
  
  
  1. void CompositionActionLayer::onRepeatForever(CCObject* pSender)
  2. {
  3. CCSpriteBatchNode *mgr = static_cast<CCSpriteBatchNode *>(this->getChildByTag(4));
  4. // 飞行喷火模拟动画
  5. CCAnimation *animation = CCAnimation::animation();
  6. animation->setName("flight");
  7. animation->setDelay(0.1f);
  8. for (int i = 0; i < 3; ++i)
  9. {
  10. float x = static_cast<float>(i % 3);
  11. animation->addFrameWithTexture(mgr->getTexture(), CCRectMake(x * 32, 0, 31, 30));
  12. }
  13. CCAnimate *action = CCAnimate::actionWithAnimation(animation);
  14. // 将该动画作为精灵的本征动画,一直运行。
  15. flight->runAction(CCRepeatForever::actionWithAction(action));
  16. CCSize s = CCDirector::sharedDirector()->getWinSize();
  17. flight->setRotation(0.0f);
  18. flight->setPosition(ccp(100, 50));
  19. // 创建第二个连续无限期动作序列,叠加两者形成完整效果。
  20. ccBezierConfig bezier;
  21. bezier.controlPoint_1 = ccp(0, s.height / 2);
  22. bezier.controlPoint_2 = ccp(300, -s.height / 2);
  23. bezier.endPosition = ccp(300, 100);
  24. CCFiniteTimeAction *action1 = CCBezierBy::actionWithDuration(3.0f, bezier);
  25. CCFiniteTimeAction *action2 = CCTintBy::actionWithDuration(0.5f, 0, 255, 255);
  26. CCFiniteTimeAction *action3 = CCSpawn::actions(action1, CCRepeat::actionWithAction(action2, 4), NULL);
  27. CCFiniteTimeAction *action4 = CCSpawn::actions(action1->reverse(), CCRepeat::actionWithAction(action2, 4), NULL);
  28. // CCSequence的actions成员函数返回的是CCFiniteTimeAction指针类型,
  29. // 而CCRepeatForever的actionWithAction接受的是CCActionInterval指针类型,
  30. // 所以这里需要强转一下,转成CCSequence指针类型,
  31. // 只要保证序列中有2个或2个以上的动作,这么做是绝对没有问题的。
  32. flight->runAction(CCRepeatForever::actionWithAction(static_cast<CCSequence *>(CCSequence::actions(action3, action4, NULL))));
  33. }

————————————————————————————————————————————————————————————————————————————————

创建剪切精灵

local man = CCSprite:create("man.png")
man:setTextureRect(CCRectMake(0,0,50,50))

CCRectMake(x, y, width, height)   x ,y 为起始点坐标,图像的左上角为(0,0)点 ,向右x逐渐增大,向下y逐渐增大,width为正值则向右切,负值向左切;height为正值则向下切,为负值则向上切

 
——————————————————————————————————————————————————————————————————————————————
当一张图片被加载到内存后,它是以纹理的形式存在的。纹理是什么东西呢?纹理就是一块内存,这块内存中存放的是按照指定的像素格式填充的图片像素信息。它被最终作为三角面着色所依据的数据源。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值