cocoster 使用过程知识点
1.重复执行某个动画,需要重新调用repeatForever()方法;不能直接在action后面以链式的方式添加repeatForever()
ex: var seq = aciton;
var repeat = seq.repeatForever();
2.如果需要使用cc.loader.loadRes()动态加载资源考虑的资源url兼容问题 ,亲测creater1.9版本,将需要动态加载的资源放在assets/resources下面。如果一份资源不需要由脚本直接动态加载,那么千万不要放在 resources 文件夹里。
3.手动设置Node节点的层级别node.setSiblingIndex();
4.cocosCreater在使用过程中,同一个变量都会有缓存,而且很厉害。为了避免这样可以将变量名改动一下。
5.关于Animation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var animation = this.node.getComponent(cc.Animation);
// 注册
animation.on('play', this.onPlay, this);
// 取消注册
animation.off('play', this.onPlay, this);
// 对单个 cc.AnimationState 注册回调
var anim1 = animation.getAnimationState('anim1');
anim1.on('lastframe', this.onLastFrame, this);

// 动态创建 Animation Clip:
var animation = this.node.getComponent(cc.Animation);
// frames 这是一个 SpriteFrame 的数组.
var clip = cc.AnimationClip.createWithSpriteFrames(frames, 17);
clip.name = "anim_run";
clip.warpMode = cc.WarpMode.Loop;

// 添加帧事件
clip.events.push({
frame: 1, // 准确的时间,以秒为单位。这里表示将在动画播放到 1s 时触发事件
func: "frameEvent", // 回调函数名称
params: [1, "hello"] // 回调参数
});

animation.addClip(clip);
animation.play('anim_run');

6.定义在每个组件里面的properties里面的变量无效。一定要onLoad里面初始化,不然在私有函数里面获取到该变量是一个字符串

1
2
3
4
5
6
7
8
cc.Class({
properties : {
_var : 11,
}.
onLoad(){
this._var = 11;
}
})