12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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;
- }
- }
|