49 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-01-11 18:09:18 +08:00
cc.Class({
extends: cc.Component,
2023-01-13 11:25:20 +08:00
properties: {
animNode: {
type: cc.Node,
default: null
},
},
2023-01-11 18:09:18 +08:00
ctor() {
this.lastUsed = -1;
this.bulletLocalId = -1;
this.speciesName = null;
},
2023-01-11 22:24:31 +08:00
setSpecies(speciesName, fireballBullet, rdf) {
2023-01-11 18:09:18 +08:00
if (speciesName == this.speciesName) return;
2023-01-13 11:25:20 +08:00
if (null != this.speciesName) {
for (let k in this.animNode.children) {
const child = this.children[k];
if (!child.active) continue;
if (child == effAnimNode || child.name == speciesName) continue;
child.active = false;
}
}
2023-01-11 18:09:18 +08:00
this.speciesName = speciesName;
2023-01-13 11:25:20 +08:00
this.effAnimNode = this.animNode.getChildByName(this.speciesName);
2023-01-11 18:09:18 +08:00
this.effAnimNode.active = true;
2023-01-13 14:55:56 +08:00
this.updateAnim(speciesName, fireballBullet, rdf);
2023-01-11 18:09:18 +08:00
},
2023-01-11 22:24:31 +08:00
onLoad() {},
updateAnim(speciesName, fireballBullet, rdf) {
2023-01-13 11:25:20 +08:00
this.animComp = this.effAnimNode.getComponent(cc.Animation);
2023-01-11 22:24:31 +08:00
// Update directions
if (this.animComp && this.animComp.node) {
if (0 > fireballBullet.DirX) {
2023-01-13 11:25:20 +08:00
this.animNode.scaleX = (-1.0);
2023-01-11 22:24:31 +08:00
} else if (0 < fireballBullet.DirX) {
2023-01-13 11:25:20 +08:00
this.animNode.scaleX = (1.0);
2023-01-11 22:24:31 +08:00
}
}
this.animComp.play(speciesName);
2023-01-11 18:09:18 +08:00
},
});