基本动作
使用 MoveBy
完成节点对象在一个设置的时间后移动。
C++
旋转
使用 RotateTo
RotateBy
完成节点对象在一个设置的时间后顺时针旋转指定角度。
C++
auto mySprite = Sprite::create("mysprite.png");
// Rotates a Node to the specific angle over 2 seconds
auto rotateTo = RotateTo::create(2.0f, 40.0f);
mySprite->runAction(rotateTo);
// Rotates a Node clockwise by 40 degree over 2 seconds
auto rotateBy = RotateBy::create(2.0f, 40.0f);
使用 ScaleBy
ScaleTo
完成节点对象的比例缩放。
使用 FadeIn
FadeOut
完成节点对象的淡入,淡出。 FadeIn
修改节点对象的透明度属性,从完全透明到完全不透明,FadeOut
相反。
C++
// fades in the sprite in 1 seconds
auto fadeIn = FadeIn::create(1.0f);
mySprite->runAction(fadeIn);
// fades out the sprite in 2 seconds
auto fadeOut = FadeOut::create(2.0f);
mySprite->runAction(fadeOut);
色彩混合
使用 TintTo
TintBy
,将一个实现了 NodeRGB
协议的节点对象进行色彩混合。
C++
C++
auto mySprite = Sprite::create("mysprite.png");
// now lets animate the sprite we moved
Vector<SpriteFrame*> animFrames;
animFrames.reserve(12);
animFrames.pushBack(SpriteFrame::create("Blue_Front1.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Front3.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Left1.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Left2.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Left3.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Back1.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Back2.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Back3.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Right1.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Right2.png", Rect(0,0,65,81)));
animFrames.pushBack(SpriteFrame::create("Blue_Right3.png", Rect(0,0,65,81)));
// create the animation out of the frames
Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
Animate* animate = Animate::create(animation);
mySprite->runAction(RepeatForever::create(animate));
变速运动
变速动作可以让节点对象具有加速度,产生平滑同时相对复杂的动作,所以可以用变速动作来模仿一些物理运动,这样比实际使用物理引擎的性能消耗低,使用起来也简单。当然你也可以将变速动作应用到动画菜单和按钮上,实现你想要的效果。
Cocos2d-x 支持上图中的大部分变速动作,实现起来也很简单。我们来看个例子,一个精灵从屏幕顶部落下然后不断跳动:
C++
复杂的动作很难在这样的文本里表示,要是看效果的话最好去运行一下本指南的 ,或者运行引擎代码的测试项目 cpp-tests
,在子菜单 中有基本的动作效果展示。
原文: http://docs.cocos.com/cocos2d-x/manual/zh/actions/basic.html