基本动作

    使用 MoveBy 完成节点对象在一个设置的时间后移动。

    旋转

    使用 RotateTo RotateBy 完成节点对象在一个设置的时间后顺时针旋转指定角度。

    1. auto mySprite = Sprite::create("mysprite.png");
    2. // Rotates a Node to the specific angle over 2 seconds
    3. auto rotateTo = RotateTo::create(2.0f, 40.0f);
    4. mySprite->runAction(rotateTo);
    5. // Rotates a Node clockwise by 40 degree over 2 seconds
    6. auto rotateBy = RotateBy::create(2.0f, 40.0f);

    基本动作  - 图2

    使用 FadeIn FadeOut 完成节点对象的淡入,淡出。 FadeIn 修改节点对象的透明度属性,从完全透明到完全不透明,FadeOut 相反。

    1. // fades in the sprite in 1 seconds
    2. auto fadeIn = FadeIn::create(1.0f);
    3. mySprite->runAction(fadeIn);
    4. // fades out the sprite in 2 seconds
    5. auto fadeOut = FadeOut::create(2.0f);
    6. mySprite->runAction(fadeOut);

    基本动作  - 图4

    色彩混合

    使用 TintTo TintBy,将一个实现了 NodeRGB 协议的节点对象进行色彩混合。

    使用 Animate 对象可以很容易的通过每隔一个短暂时间进行图像替代的方式,实现一个翻页效果。下面是一个例子:

    1. auto mySprite = Sprite::create("mysprite.png");
    2. // now lets animate the sprite we moved
    3. Vector<SpriteFrame*> animFrames;
    4. animFrames.reserve(12);
    5. animFrames.pushBack(SpriteFrame::create("Blue_Front1.png", Rect(0,0,65,81)));
    6. animFrames.pushBack(SpriteFrame::create("Blue_Front3.png", Rect(0,0,65,81)));
    7. animFrames.pushBack(SpriteFrame::create("Blue_Left1.png", Rect(0,0,65,81)));
    8. animFrames.pushBack(SpriteFrame::create("Blue_Left2.png", Rect(0,0,65,81)));
    9. animFrames.pushBack(SpriteFrame::create("Blue_Left3.png", Rect(0,0,65,81)));
    10. animFrames.pushBack(SpriteFrame::create("Blue_Back1.png", Rect(0,0,65,81)));
    11. animFrames.pushBack(SpriteFrame::create("Blue_Back2.png", Rect(0,0,65,81)));
    12. animFrames.pushBack(SpriteFrame::create("Blue_Back3.png", Rect(0,0,65,81)));
    13. animFrames.pushBack(SpriteFrame::create("Blue_Right1.png", Rect(0,0,65,81)));
    14. animFrames.pushBack(SpriteFrame::create("Blue_Right2.png", Rect(0,0,65,81)));
    15. animFrames.pushBack(SpriteFrame::create("Blue_Right3.png", Rect(0,0,65,81)));
    16. // create the animation out of the frames
    17. Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
    18. Animate* animate = Animate::create(animation);
    19. mySprite->runAction(RepeatForever::create(animate));

    变速运动

    变速动作可以让节点对象具有加速度,产生平滑同时相对复杂的动作,所以可以用变速动作来模仿一些物理运动,这样比实际使用物理引擎的性能消耗低,使用起来也简单。当然你也可以将变速动作应用到动画菜单和按钮上,实现你想要的效果。

    Cocos2d-x 支持上图中的大部分变速动作,实现起来也很简单。我们来看个例子,一个精灵从屏幕顶部落下然后不断跳动: