action

来源:互联网 发布:上半年经济数据 编辑:程序博客网 时间:2024/05/17 23:23

   cc.sequence               创建动作序列

 cc.delaytime(2)             延时多少秒

cc.rotateto rotatebt   以锚点为中心旋转 

Action对象是随着时间改变Node的属性。任何一个以Node为基类的对象都有可执行的动作对象。

例如,你可以在一个时间段内将Sprite精灵从一个位置移动到另一个位置。

如下为MoveToMoveBy两个动作的实例:




 moveTo和 Moveby两个动作的实例:

//Move sprite to position 50,10 in 2 seconds

var moveTo =cc.move To ( 2,cc.p(50,10));

my Sprite1.runAction(moveTo);

//Move sprite 20 points to right in 2 seconds

var moveBy = cc.moveBy(2,cc.p(20,0));

mySprite1,runAction(moveBy);

By和To的区别:

By相对于节点是相对的

To相对于节点是绝对的

var mySprite = new cc.Sprite("mySprite.png");

 mySprite.setPosition(200,256);

//MoveBy - lets move the sprite by 500 on the x axis over 2 seconds

//MoveBy is relative - since x = 200+200 move =x is now 400 after the move

var moveBy = cc.moveBy(2,cc.p(500, mySprite.y));

//MoveTo -lets move the new sprite to 300  x 256 over 2 seconds

// MoveTo is ab solute - The sprite gets moved to 300 x256 regardless of

// where it is located now.

var moveTo = cc.moveTo(2,cc.p(300,mySprite.y));

var delay = 2.0;

var seq =cc. sequence(moveBy,delay,moveTo);

mySprite.runAction(seq);  

   旋转 Rotate

var mySprite = new cc. sprite("mySprite.png");

var rotateTo =cc. rotateTo(2,40);

mySprite.runAction(moveTo);


var rotateBy = cc.rotateBy(2,40);

my Sprite. runAction(rotateBy);

     

缩放(Scale)
var mySprite =new cc.Sprite ("mySprite.png");

var scaleBy = cc.scaleBy(2.0,3.0);
mySprite.runAction(scaleBy);

  

var scaleBy =cc.scaleBy(2.0,3.0,3.0);

my Sprite.runAction(scaleBy);


0 0
原创粉丝点击