Phaser Uncaught ReferenceError:游戏未定义

时间:2015-09-16 15:55:11

标签: javascript html5 requirejs phaser-framework

我正在使用Phaser创建我的第一个游戏并使用requirejs。

我写了这段代码:

requirejs.config({
  baseUrl: 'game',
  paths: {
    Phaser: 'js/phaser.min',
    BootState: 'states/boot',
    MenuState: 'states/menu',
    PreloadState: 'states/preload',
  }
});

var BootState = require(['Phaser']);
var MenuState = require(['MenuState']);
var PreloadState = require(['PreloadState']);

new Phaser.Game(1334, 750, Phaser.AUTO, 'bird-reborn');

// Game States

game.state.add('boot', BootState);
game.state.add('menu', MenuState);
game.state.add('play', PlayState);
game.state.add('preload', PreloadState);

game.state.start('boot');

并出现此错误Uncaught ReferenceError: game is not defined

我该如何解决这个问题? 谢谢!

1 个答案:

答案 0 :(得分:1)

替换此行:

new Phaser.Game(1334, 750, Phaser.AUTO, 'bird-reborn');

由此:

var game = new Phaser.Game(1334, 750, Phaser.AUTO, 'bird-reborn');