← 返回博客
phaser2022-01-08 12:16:031 分钟 · 205 3947

vite2+vue3+phaser学习phaser案例

研究如何使用vite2+vue3+phaser来配合使用的方法,项目目的是为了学习phaser官网的案例,代码已上传github

#vue3#vite2#phaser

github地址:https://github.com/ningbnii/vite2_vue3_phaser_demos

项目演示地址:http://wxbuluo.com/phaser/

项目持续更新中

1、切换路由后,发现update仍在执行。解决方案:在onUnmounted中销毁场景

onUnmounted(() => {
  for (let key in game.scene.keys) {
    if (game.scene.keys.hasOwnProperty(key)) {
      game.scene.stop(key);
      game.scene.keys[key] = undefined;
    }
  }
});

2、发现import test_json from '../../assets/test.json'引入json的方法,有些格式无法解析,使用import.meta.url方式引入则可以

    const sea_json = new URL("../../assets/sea_creatures_json.json", import.meta.url).href

3、发现图片放到public/assets/下面更合适,这样引入图片就不用import了

相关推荐

本文为原创文章,采用CC BY-NC-SA 4.0协议授权,转载请保留署名与原文链接。原文链接:https://www.wxbuluo.com/article/48