const game = new Phaser.Game(375, 667, Phaser.AUTO); const helloState = { preload: function () { game.stage.backgroundColor = "#a8d4bf"; game.load.image("logo", "/source/logo.png"); }, create: function () { const text = game.add.text(game.world.centerX, 25, "hello world", {fill: '#fff'}); text.anchor.set(0.5); const logo = game.add.image(game.world.centerX, game.world.centerY, "logo"); logo.anchor.set(0.5); } } game.state.add("helloState", helloState); game.state.start("helloState");
你用的是适配小游戏之后的phaser,由于GameGlobal判断不太严谨,导致浏览器环境报错,更严谨的做法: if(typeof GameGlobal != 'undefined'){}
代码已改 可以在这下载 https://gitee.com/codeveryday/phaser-ce_wechat
在build目录
Uncaught ReferenceError: GameGlobal is not defined
<anonymous> http://127.0.0.1:8080/js/phaser.js:45
<anonymous> http://127.0.0.1:8080/js/phaser.js:51
Uncaught ReferenceError: Phaser is not defined
<anonymous> http://127.0.0.1:8080/js/main.js:1
浏览器报上面错误