【问题标题】:Can't Get Phaser To Work无法让移相器工作
【发布时间】:2014-05-24 20:33:58
【问题描述】:

在过去的几天里,我一直无法让 Phaser 工作:只是想测试一个 hello world 程序。我完全按照 Phaser 网站上的说明进行操作,但它仍然不适合我。

我正在使用 node.js。

这里是 index.html:

<!DOCTYPE html>
<html>

<head>
     <meta charset="utf-8" />
     <title>Hello World</title>

     <style>
        #game_div {
        width: 500px;
        margin: auto;
        margin-top: 50px;
      }
    </style>

    <script type="text/javascript" src="phaser.min.js"></script>
    <script type="text/javascript" src="main.js"></script>
</head>

<body>

    <div id="game_div"> </div>

</body>

</html>

这里是 main.js:

/*jslint node: true */
"use strict";
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');

var main_state = {

    preload: function () {
        game.load.image('hello', 'assets/hello.png');
    },

    create: function () {
        this.hello_sprite = game.add.sprite(200, 245, 'hello');
    },

    update: function () {
        this.hello_sprite.angle += 1;
    }
}

game.state.add('main', main_state);
game.state.start('main');

它给我的错误是:

“Phaser”在定义之前使用。
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');

我确实尝试过寻找解决方案,但我找不到任何问题。我对 JavaScript 和 Phaser 还是很陌生。

【问题讨论】:

  • 加载 index.html 时会发生什么?控制台有没有说什么?
  • 控制台显示:Phaser v2.0.2 - WebGL - WebAudio phaser.io ♥♥♥ phaser.min.js:7 Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross- file:///C:/Users/Demx/Desktop/Programming/Testing/assets/hello.png 的原始图像可能无法加载。 phaser.min.js:4
  • 听起来你需要在网络服务器上运行它
  • 如果您在 Phaser 官方论坛上发布您的问题,您一定会得到答案:html5gamedevs.com/forum/14-phaser

标签: javascript html phaser-framework


【解决方案1】:

在显示为chrome.exe 的谷歌浏览器快捷方式中,尝试添加--allow-file-access-from-files,然后打开浏览器并加载适用于linux 的网页,它将是/usr/bin/google-chrome-stable %U --allow-file-access-from-files 它对我有用,即使在本地运行时图像也已加载

【讨论】:

  • 遇到了与 OP 相同的问题,您的解决方案对我不起作用。
【解决方案2】:

上面的 SecurityError 指向问题的根源:您是直接在浏览器中打开文件,在这种情况下您无权访问这样的本地文件。它需要通过网络服务器提供服务。如果您需要任何帮助,我们将在网站上的入门指南中介绍。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-29
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多