9 Phaser3-多场景切换

效果展示

在这里插入图片描述

关键技术点

  • 使用this.scene.start打开新场景
  • 打开新场景之前要先设置场景不可见,使用this.scene.setVisible(false)
  • 打开新场景后要设置场景可见,使用this.scene.setVisible(true)

部分主要文件代码

BootScene.js

import { Scene } from 'phaser'

export default class BootScene extends Scene {
  constructor () {
    super({ key: 'BootScene' });
  }
  showMsg = null

  create () {
    this.scene.start('PlayScene')
  }
}

PlayScene.js

import { Scene } from 'phaser'

export default class PlayScene extends Scene {
  constructor () {
    super({ key: 'PlayScene' })
  }

  create () {
    // 添加文字
    this.showMsg = this.add.text(16, 16, 'Play Scene!',
        { fontSize: '32px', fill: '#fff' });

    this.input.on("pointerdown",function(){
      this.scene.setVisible(false)
      this.scene.start('OneScene')
      this.scene.setVisible(true);
    },this);
  }
}

OneScene.js

import { Scene } from 'phaser'
export default class PlayScene extends Scene {
  constructor () {
    super({ key: 'OneScene' })
  }

  create () {
    // 添加文字
    this.showMsg = this.add.text(16, 16, 'One Scene!',
        { fontSize: '32px', fill: '#fff' });

    this.input.on("pointerdown",function(){
      this.scene.setVisible(false)
      this.scene.start('TwoScene')
      this.scene.setVisible(true);
    },this);
  }
}

TwoScene.js

import { Scene } from 'phaser'

export default class PlayScene extends Scene {
  constructor () {
    super({ key: 'TwoScene' })
  }

  create () {
    // 添加文字
    this.showMsg = this.add.text(16, 16, 'Two Scene!',
        { fontSize: '32px', fill: '#fff' });

    this.input.on("pointerdown",function(){
      this.showMsg.setVisible(false)
      this.over = this.add.text(16, 16, 'Over!',
          { fontSize: '32px', fill: '#fff' });
    },this);
  }
}

本节完整代码下载地址

https://github.com/biwow/phaser3/tree/main/code/9

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容[1],该引用提到了使用TypeScript编写的3D库three.js和ammo.js,可用于Web、移动和PC平台,它可以为您的项目提供物理学特性,并为Phaser 3游戏引入三维功能。您可以访问相应的网站以获取文档和示例。 而根据引用,无法找到G:\html\threejs-test\phaser3-start\01-phaser\node_modules\src文件夹。请确认该路径是否正确,并确保该文件夹存在。如果该文件夹确实不存在,您可以尝试解决该问题的方法包括检查文件路径是否正确、重新安装相应的模块或库,以及确保您的项目配置正确。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [enable3d:用于Three.js的:joystick_selector:独立3D框架物理(使用ammo.js)Phaser 3的3D扩展](https://download.csdn.net/download/weixin_38750761/14948289)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Google搜索关键字](https://blog.csdn.net/weixin_30359021/article/details/99600212)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值