| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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()
- }
- }
- }
- }
|