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