【问题标题】:How to add background image to my phaser game?如何为我的移相器游戏添加背景图像?
【发布时间】:2020-07-07 20:18:37
【问题描述】:

我想为我的游戏添加背景图片/场景。此代码不起作用。

        const config= {
            type: Phaser.AUTO,
            height: 675,
            width: 675,
            scene: {
                preload,
                create,
                update,
            }
        }
        const game = new Phaser.Game(config)
        const gameState ={
        }
        function preload() {
            this.load.image('background','/background.jpg');
        }
        function create() {
            gameState.move = this.add.circle(325,325,25,'0xffffff');
            let bg=this.add.image(0,0,'background');            
}

function update() {
}

我能做什么?我是移相器游戏的新手。 我不认为 URL 不正确。但这是输出:enter image description here

【问题讨论】:

    标签: html phaser


    【解决方案1】:

    可能图片的网址不正确。 docs 表示 URL 可以是相对的或绝对的。如果图像在文件系统中与您的 JavaScript 文件处于同一级别,则在您的 preload 函数中,您可以尝试:

    this.load.image('background','background.jpg');

    this.load.image('background','./background.jpg');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      相关资源
      最近更新 更多