对象结构
Node0
-----Node1
-----------Sprite0
脚本Test绑在Node0上,指定n跟sprite分别为Node1跟Sprite0.
我先在start方法里把把Sprite0的state设置为gray;Node1的active设置为fasle,再把Sprite0的state设置为Normal;
然后过了一秒之后,把Node1的active设置为true,并且把Sprite0的state设置为Normal;
但是Sprite的state虽然是Normal,但是颜色并没有变为正常,还是灰色。
Test.js
cc.Class({
extends: cc.Component,
properties: {
n :{
default : null,
type : cc.Node
},
sprite :{
default : null,
type : cc.Sprite
}
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
this.timer = 0;
this.sprite.setState(cc.Sprite.State.GRAY)
this.n.active = false;
this.sprite.setState(cc.Sprite.State.NORMAL)
},
update (dt) {
if(this.timer < 1){
this.timer += dt;
if(this.timer > 1){
this.timer -= 1;
if(this.n.active){
}else{
this.n.active = true;
this.sprite.setState(cc.Sprite.State.NORMAL)
}
}
}
},
});