http://www.cocos2d-x.org/docs/programmers-guide/actions/index.html
一、简介:Actions
Action 对象字如其名。他使得一个节点Node执行属性的改变。Action对象允许节点Node属性及时的转换。任何node的子类能使用执行Action对象。例如,你可以移动一个Sprite从一个位置到另一个位置且在一段时间内。
MoveTo and MoveBy 的action例子
//move sprite to postion 50,20 in 2seconds
var moveTo = new cc.MoveTo(2,cc._p(50,10));
mySprite1.runAction(moveTo);
//move sprite 20 points to right in 2 seconds
var moveBy = new cc.MoveBy(2,cc._p(20,0));
mySprite.runAction(moveBy);
1、By and To what is the difference?
你将注意到每个Action都有By和To版本。为什么?因为他们完成的方式不同。A By 与Node的当前状态相关。A To 的action是绝对的,意思他和当前节点的状态没有关系。下面是例子。
var mySprite = new cc.Sprite(res.mysprite_png);
mySprite.setPosition(cc._p(200,256));
//moveBy lets move the sprite by 500 on the x axis over 2seconds
//moveBy is relative -since x =200+200 voe = x is now 400 after the move
var moveBy = new cc.MoveBy(2,cc._p(500,mySprite.y));
// MoveTo - lets move the new sprite to 300 x 256 over 2 seconds// MoveTo is absolute - The sprite gets moved to 300 x 256 regardless of// where it is located now.varmoveTo =newcc.MoveTo(2, cc._p(300, mySprite.y));// Delay - create a small delayvardelay =newcc.DelayTime(1);varseq =newcc.Sequence(moveBy, delay, moveTo);
mySprite.runAction(seq);
二、Basic Actions and how to run them
Basic action 通常是单例,因此完成的是一个对象。
1、Move
在一个设定的时间内移动节点。
var mySprite = new cc.Sprite(res.mysprite_png);
//Move a sprite to a specific location over 2 seconds
var moveTo = new cc.MoveTo(2,cc._p(50,0));
mySprite.runAction(moveTo);
//Move asprite 50pixels to0 the right ,and 0 pixels to the top voer 2 seconds.
var moveBy = new cc.MoveBy(2,cc._p(50,0));
mySprite.runAction(moveBy);
三、Rotate
2秒内顺时针旋转
var mySprite = new cc.Sprite(res.mysprite_png);
//Rotates a Node to the specific angle voer 2 seconds
var rotateTo = new cc.RotateTo(2.0,40.0);
mySprite.runAction(rotateTo);
//Rotates a Node clockwise by 40 degree over 2 seconds
var rotateBy = new cc.RotateBy(2.0,40.0);
mySprite.runAction(rotateBy);
四、Scale
varmySprite =newcc.Sprite(res.mysprite_png);// Scale uniformly by 3x over 2 secondsvarscaleBy =newcc.ScaleBy(2.0,3.0);
mySprite.runAction(scaleBy);// Scale X by 5 and Y by 3x over 2 secondsvarscaleBy =newcc.ScaleBy(2.0,3.0,3.0);
mySprite.runAction(scaleBy);// Scale to uniformly to 3x over 2 secondsvarscaleTo =newcc.ScaleTo(2.0,3.0);
mySprite.runAction(scaleTo);// Scale X to 5 and Y to 3x over 2 secondsvarscaleTo =newcc.ScaleTo(2.0,3.0,3.0);
mySprite.runAction(scaleTo);
五、Fade In/Out
http://www.cocos2d-x.org/docs/programmers-guide/actions/index.html