很多童鞋不是很明白cocos studio里的帧动画应该怎么用,在代码里如何去调用cocos studio里导出的json格式文件。
下面这段代码简单的展示了,怎么读取json文件和设置帧事件回调:
demoLayer = cc.Layer.extend({
ctor:function(){
this._super();
......
this.initUI();
return true;
},
initUI:function(){
.....
var mainScene = ccs.load(res.loadScene_json);
//这里的0是起始帧,115是结束帧(请更加自己的帧动画自己填写),false是只播放一次,
mainScene.action.gotoFrameAndPlay(0,115,false);
mainScene.action.setFrameEventCallFunc(this.frameEvent);//设置帧事件回调函数
mainScene.node.runAction(mainScene.action);
this.addChild(mainScene.node);
},
frameEvent:function(frame){
<span style="white-space:pre"> </span>//帧事件的标签在cocos studio里进行设置,这里判断是不是你设置的帧事件标签字符串
if(frame.getEvent() == "帧事件"){
cc.log("我是帧事件");
};
}
});