本节课学习到了节点的Action。Action有很多种,如:
RotateTo,RotateBy,MoveBy,MoveTo,Skewto,SkewBy,JumpTo,jumpBy等。每个动作所包含的参数也是不一样的。但是都包括了执行时间和目标位置的坐标。下面是我本节课的代码:
var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
this._super();
var size = cc.winSize;
var npc=new cc.Sprite(res.npc02_png);//一会要增加这个文件在src/resource.js
npc.setTag(100);
npc.setPosition(cc.winSize.width/2,cc.winSize.height/2);
this.addChild(npc);
var ItemGo = new cc.MenuItemFont("开始",this.callback,this);
ItemGo.setFontName("黑体");
ItemGo.setFontSize(40);
var menu = new cc.Menu(ItemGo);
ItemGo.setAnchorPoint(0,0);
menu.setPosition(50,200);
this.addChild(menu);
return true;
},
callback:function(){
var npc = this.getChildByTag(100);
npc.runAction(new cc.MoveBy(0.2,cc.p(15,0)));
if(npc.getPositionX() > cc.winSize.width){
npc.setPositionX(0);
}
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
最后附上作业链接:
http://www.cocoscvp.com/usercode/2016_04_19/b7b7c19d598323786d91ff429d7b09edecb68b29/
原文链接:https://www.f2er.com/cocos2dx/339523.html