import {_decorator, Component, EventTouch, find, Node, ScrollView, v2, Vec2} from 'cc'; import {TestMgr} from './TestMgr'; import {AudioManage} from '../script/AudioManage'; const {ccclass, property} = _decorator; @ccclass('IntroMgr') export class IntroMgr extends Component { private startPos: Vec2 private step: number = 0 private turnInterval: number = 10 private readTime: number[] = [31, 21.5, 17.5] protected onLoad(): void { this.node.getChildByName("controller").on("click", () => { }, this) this.node.getChildByName("controller").on(Node.EventType.TOUCH_START, this.onTouchStart, this) this.node.getChildByName("controller").on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this) this.node.getChildByName("controller").on(Node.EventType.TOUCH_END, this.onTouchEnd, this) this.node.getChildByName("controller").on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this) this.node.getChildByName("Button").off("click") this.node.getChildByName("Button").on("click", () => { this.unschedule(this.goIntro); this.node.active = false // this.showTitle() find("Canvas").getComponent(TestMgr).showTitle() // find("Canvas/noclick2").active = true }, this) this.node.getChildByName("soundBtn").off("click") this.node.getChildByName("soundBtn").on("click", () => { AudioManage.instance.pauseMusic() AudioManage.instance.playSoundCallback("sound/intro" + this.step) }, this) } start() { } update(deltaTime: number) { } public startIntro() { AudioManage.instance.pauseMusic() AudioManage.instance.playSoundCallback("sound/intro" + this.step) const len = this.node.getChildByName("Layout").children.length // this.goIntro(len) this.step = 0 this.schedule(this.goIntro, this.readTime[this.step], Number.POSITIVE_INFINITY, 0); } private goIntro() { const len = this.node.getChildByName("Layout").children.length this.step++ if (this.step >= len) { this.step = 0 } this.turnCard() // console.log("000000000000= " + this.step); } private turnCard() { AudioManage.instance.pauseMusic() this.unschedule(this.goIntro); const len = this.node.getChildByName("Layout").children.length const offset = 1 / (len - 1) // console.log("000000000000= " + this.step); this.node.getChildByName("ScrollView").getComponent(ScrollView).scrollTo(v2(offset * this.step, 0), 0.5) this.node.getChildByName("Layout").children.forEach((tnode) => { tnode.getChildByName("icon").active = false }) this.node.getChildByName("Layout").children[this.step].getChildByName("icon").active = true this.schedule(this.goIntro, this.readTime[this.step], Number.POSITIVE_INFINITY, 0); this.scheduleOnce(function () { AudioManage.instance.playSoundCallback("sound/intro" + this.step) }, 0.5); } protected onDisable(): void { this.disTouch() } public disTouch() { this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this) this.node.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this) this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this) this.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this) } private onTouchStart(event: EventTouch) { this.startPos = event.getUILocation() } private onTouchMove(event: EventTouch) { } private onTouchEnd(event: EventTouch) { const endPos = event.getUILocation() if (this.startPos.x > endPos.x) {//向左移,下一张 const len = this.node.getChildByName("Layout").children.length if ((this.step + 1) < len) { this.step++ this.turnCard() } } else if (this.startPos.x < endPos.x) {//向右移,上一张 const len = this.node.getChildByName("Layout").children.length if ((this.step - 1) >= 0) { this.step-- this.turnCard() } } } private onTouchCancel(event: EventTouch) { const endPos = event.getUILocation() if (this.startPos.x > endPos.x) {//向左移,下一张 const len = this.node.getChildByName("Layout").children.length if ((this.step + 1) < len) { this.step++ this.turnCard() } } else if (this.startPos.x < endPos.x) {//向右移,上一张 const len = this.node.getChildByName("Layout").children.length if ((this.step - 1) >= 0) { this.step-- this.turnCard() } } } }