【问题标题】:Not able to see image loaded with Phaser 3.24.1无法看到使用 Phaser 3.24.1 加载的图像
【发布时间】:2021-03-01 14:50:06
【问题描述】:

我刚开始使用移相器,我尝试做的第一件事是使用作为安装演示的图像项目探索“hello world”。我在文件夹的同一位置有 index.html、phaser.png 和 phaser.min.js。我正在运行 Node.js 并使用 npm http-server 启动它。当我实际这样做时,我只看到一个大小为 800x600 的黑色方块,没有别的。代码和他的一样:

<html>
    <head>
        <meta charset="UTF-8" />
        <title>hello phaser!</title>
        <script src="phaser.min.js"></script>
    </head>
    <body>
    <script type="text/javascript">
    window.onload = function() {
        var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
        function preload () {
            game.load.image('logo', 'phaser.png');
        }
        function create () {
            var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'logo');
            logo.anchor.setTo(0.5, 0.5);
        }
    };
    </script>
    </body>
</html>

这里缺少什么?

【问题讨论】:

    标签: phaser


    【解决方案1】:

    您正在尝试在导入 Phaser3 时混合旧样式的 Phaser2 Game 构造函数,因此您的回调不起作用。

    在此处查看 Phaser3“Hello World”教程以获取更多工作代码:https://phaser.io/tutorials/getting-started-phaser3/part5

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 2016-12-12
      • 2014-04-11
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多