import { _decorator, Component, Node ,Button,director, PageView, NodeEventType} from 'cc'; const { ccclass, property } = _decorator; @ccclass('SelectScene') export class SelectScene extends Component { @property(Node) pageView:Node = null; currentPageIndex:number = null; start() { this.currentPageIndex = this.pageView.getComponent(PageView).getCurrentPageIndex(); let BtnHome = this.node.getChildByPath("UIButton/BtnHome"); BtnHome.on(Button.EventType.CLICK,this.onBtnHome,this); let BtnHelp = this.node.getChildByPath("UIButton/BtnHelp"); BtnHelp.on(Button.EventType.CLICK,this.onBtnHelp,this); let BtnLeft = this.node.getChildByPath("UIButton/BtnLeft"); BtnLeft.on(Button.EventType.CLICK,this.onBtnLeft,this); let BtnRight = this.node.getChildByPath("UIButton/BtnRight"); BtnRight.on(Button.EventType.CLICK,this.onBtnRight,this); let touchArea = this.node.getChildByPath("TouchArea"); touchArea.on(NodeEventType.TOUCH_START,this.onTouchStart,this); touchArea.on(NodeEventType.TOUCH_END,this.onTouchEnd,this); } onBtnHome(){ //console.log("LoginScene"); director.loadScene("LoginScene") } onBtnHelp(){ console.log("HelpScene"); //director.loadScene(""); } onBtnLeft(){ // if(this.currentPageIndex < 0){ // this.currentPageIndex = 0; // } // else{ // this.currentPageIndex = this.currentPageIndex - 1; // } this.currentPageIndex = Math.max(0, this.currentPageIndex - 1); this.pageView.getComponent(PageView).scrollToPage(this.currentPageIndex); this.pageView.getComponent(PageView).scrollToPage(this.currentPageIndex); } onBtnRight(){ // if(this.currentPageIndex == this.pageView.getComponent(PageView).getPages().length + 1){ // this.currentPageIndex = this.pageView.getComponent(PageView).getPages().length; // }else{ // this.currentPageIndex = this.currentPageIndex + 1; // } //总页数totalPages 最大索引totalPages - 1 const totalPages = this.pageView.getComponent(PageView).getPages().length; // 确保 currentPageIndex 不会超过 totalPages - 1 if (this.currentPageIndex === totalPages - 1) { this.currentPageIndex = totalPages - 1; // 保持在最后一页 } else { this.currentPageIndex = Math.min(this.currentPageIndex + 1, totalPages -1); } this.pageView.getComponent(PageView).scrollToPage(this.currentPageIndex); } onTouchStart(){ //console.log("TouchStart"); } onTouchEnd(){ director.loadScene("SelectLevel"); //console.log("TouchEnd"); } update(deltaTime: number) { } }