本节课主要学习了如何使用Animation Editor制作帧动画和如何在cocosjs环境下加载这些帧动画。首先通过查阅资料:
添加骨骼文件信息,由骨骼数据管理器管理。采用ccs.ArmatureFileInfo这个类添加动画文件,然后添加动画层,然后播放哪一帧的动画。当然在此之前一定要在我们的配置文件中加入”extensions”,只有加入这个才可以用cocostudio的内容......还有不能忘记在Resuorce.js添加.plist .png .json文件。具体代码如下: var HelloWorldLayer = cc.Layer.extend({ sprite:null, isAttack:null, ctor:function () { this._super(); var size = cc.winSize; cc.eventManager.addListener({ event:cc.EventListener.TOUCH_ONE_BY_ONE, swallowTouches:true, onTouchBegan:this.ontouchbegan.bind(this), onTouchMoved:this.ontouchmoved, onTouchEnded:this.ontouchended.bind(this) },this); //添加动画文件 ccs.armatureDataManager.addArmatureFileInfo(res.ani_attack_json); //添加动画层 var ani = new ccs.Armature("NewAnimationAttack"); //添加标记 ani.setTag(100); ani.setPosition(size.width/2,size.height/2); this.addChild(ani); return true; }, ontouchbegan: function (touch,event) { var ani = event.getCurrentTarget().getChildByTag(100); //播放刚刚添加的动画 ani.getAnimation().playWithIndex(0); this.isAttack=false; //当动画播放结束后,执行监听 ani.getAnimation().setMovementEventCallFunc(this.animationEvent,this); return true; }, animationEvent:function (armature,movementType,movementID) { var size = cc.winSize; if(!this.isAttack){ //移除之前的动画 this.removeChildByTag(100); ccs.armatureDataManager.addArmatureFileInfo(res.ani_walk_json); var ani1 = new ccs.Armature("NewAnimationWalk"); ani1.getAnimation().playWithIndex(0); ani1.getAnimation().s ani1.setPosition(size.width/2,size.height/2); this.addChild(ani1); } }, ontouchmoved:function(){ }, ontouchended: function () { } }); var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); } });
最后附上作业链接:
http://www.cocoscvp.com/usercode/3355e343a7cf923a23fbfb9cbf9551b1b6e73f48/ (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|