微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

图像未添加到场景中 -Phaser 3.5

如何解决图像未添加到场景中 -Phaser 3.5

我正在尝试学习移相器 js,但一直在弄清楚为什么我的背景图像没有显示到场景中。我尝试将图像文件移动到不同的位置,并尝试执行函数声明而不是方法,所有结果都相同。预先感谢您提供的任何指导!顺便说一句,我正在使用包裹捆绑程序代码和屏幕截图

Screenshot

首先是 main.js

import Phaser,{ Physics } from "phaser"
import { TitleScene } from "./scenes"

const GameConfig = {
  width: 800,height: 500,type: Phaser.AUTO,physics: {
    default: "arcade",arcade: {
      gravity: {
        y: 0,},};

const game = new Phaser.Game(GameConfig);

game.scene.add("title",TitleScene);

game.scene.start("title");

这是我的scenes.js文件

import Phaser,{ Textures } from "phaser"

export class TitleScene extends Phaser.Scene {
    preload() {
        this.load.image("sky","sky.png");
    }

    create() {
       this.add.image(400,250,"sky");
       const titleText = this.add.text(400,"Hello World!");
       titleText.setorigin(0.5,0.5);
     //this.add.arc(400,128,360,false,0xff0000);
        
    }
};

export class GameScene extends Phaser.Scene {
    preload() {

    }

    create() {

    }
}

解决方法

您可能需要调整为图片网址提供的相对于 from fastavro import reader,json_writer with open("json_file.json","w") as json_file: with open("avro_file.avro","rb") as avro_file: avro_reader = reader(avro_file) json_writer(json_file,avro_reader.writer_schema,avro_reader)

的路径

例如

scenes.js

https://codesandbox.io/s/stackoverflow-66878947-qhevi?file=/js/scenes.js

https://phaser.io/examples/v2/basics/01-load-an-image

,

对于任何有类似问题的人,我可以通过像这样直接导入图像来修复 2 种方法 1:import bg0 from "./assets/bg0.png" 或使用 require() 像这样: this.load.image("bg0",require("./assets/bg0.png")) 我怀疑这些都是需要的由于某些 macos 设置问题或包裹打包机问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。