[英]Phaser, Image Replaced By Green Square, No Errors, JS
I followed many Phaser tutorials online with precision, and made sure the path to the image is adequate, yet I find myself stuck with a green square with a dash across it in place for my image green square .我在网上精确地遵循了许多 Phaser 教程,并确保图像的路径是足够的,但我发现自己被一个绿色方块卡住了,我的图像绿色方块在它上面有一个破折号。
I have suspicions that perhaps it's the way I have my testing server set up, I am using parcel for this.我怀疑这可能是我设置测试服务器的方式,我为此使用包裹。 I've tried many implementations of loading images using Phaser's preLoad() function, but even the simplest one
this.load.image('testing','../../assets/user/body/moveRightAtlas.png');
我已经尝试了许多使用 Phaser 的 preLoad() function 加载图像的实现,但即使是最简单的
this.load.image('testing','../../assets/user/body/moveRightAtlas.png');
(in preLoad) and var testing=this.add.sprite(400,400,'testing');
(在预加载中)和
var testing=this.add.sprite(400,400,'testing');
(in create) still prints the square. (在创建中)仍然打印正方形。 For the path, I've tried absolute path and still does not work.
对于路径,我尝试了绝对路径,但仍然无法正常工作。 Here is how my directories are set up.
这是我的目录的设置方式。 directories .
目录。 My question is, what am I doing incorrect?
我的问题是,我做错了什么? I'm an absolute noob in Phaser, so any help is deeply appreciated, thanks.
我是 Phaser 中的绝对菜鸟,因此非常感谢任何帮助,谢谢。
(EDIT: for the directories screenshot I accidently said moveRight0, I meant moveRightAtlas.png) (编辑:对于我不小心说moveRight0的目录截图,我的意思是moveRightAtlas.png)
After reading more, it seems that the image exists but the web server I am using to test the game can't seem to load it.阅读更多后,似乎图像存在,但我用来测试游戏的 web 服务器似乎无法加载它。 So the issue is likely on the webserver.
所以问题很可能出在网络服务器上。 I am using parcel.
我正在使用包裹。
The path should be relative to the HTML file.该路径应相对于 HTML 文件。 so probably:
所以可能:
this.load.image('testing','assets/user/body/moveRightAtlas.png');
You should probably move the assets directory inside your src
and then go from there.您可能应该在您的
src
中移动资产目录,然后从那里移动 go。
Here's how this samme's repository for a working parcel setup is doing the imports: 这是用于工作包裹设置的 samme 存储库如何进行导入:
[...]
import images from './assets/*.png';
[...]
this.load.image('space', images.space);
[...]
In your case it'd probably be something like:在你的情况下,它可能是这样的:
[...]
import moveRightAtlas from './assets/user/body/moveRightAtlas.png';
[...]
this.load.image('testing', moveRightAtlas);
[...]
Check also its README for a plugin to copy the assets.还要检查其 README 以获取用于复制资产的插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.