import ccclass = cc._decorator.ccclass; import property = cc._decorator.property; import Audience from "../prefab/Audience"; @ccclass export class AudienceManager extends cc.Component { @property(cc.Node) audienceNodeList: cc.Node[] = []; @property(cc.Prefab) audiencePrefab: cc.Prefab = null; private audienceList: Audience[] = []; protected onLoad() { } protected start() { } audienceShow(comboCount) { if (comboCount < 2) { return; } let audienceNode: cc.Node = cc.instantiate(this.audiencePrefab) let initNode = this.getNode() if (!initNode) { return; } initNode.addChild(audienceNode) let targetPos: cc.Vec3 = new cc.Vec3(0, 0, 0) audienceNode.position = new cc.Vec3(initNode.position.x > 0 ? 800 : -800, 0, 0) let audience = audienceNode.getComponent(Audience) this.audienceList.push(audience) cc.tween(audienceNode) .to(0.3, {position: targetPos}) .call(() => { audience.showShadow() }).start() } audienceSigh() { //观众叹气 for (let i = 0; i < this.audienceList.length; i++) { let audience = this.audienceList[i] audience.sigh(false, 1, () => { }) } // this.audienceLeave() } audienceLeave() { if (this.audienceList.length > 0) { let index = this.audienceList.length - 1 let last = this.audienceList[index] last.exit(false, 1, () => { cc.tween(last.node) .to(0.4, {opacity: 0, scale: 0.5}) .call(() => { this.audienceList.splice(index, 1) this.audienceNodeList[index].removeAllChildren() }).start() }) } } audienceApplaud() { //关注鼓掌 for (let i = 0; i < this.audienceList.length; i++) { let audience = this.audienceList[i] audience.applaud(false, 0.5, () => { }) } } reInit() { for (let i = 0; i < this.audienceList.length; i++) { this.audienceList[i].node.destroy() } this.audienceList = [] } private getNode(): cc.Node { for (let i = 0; i < this.audienceNodeList.length; i++) { let node = this.audienceNodeList[i] if (node.children.length == 0) { return node } } return null; } }