问题描述
我尝试使用来自网络的链接和 PC 路径设置我的路径,但没有奏效,我的屏幕上曾经显示过这个绿色方块:
我的 game.ejs
文件:
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta http-equiv="X-UA-Compatible" content="IE=edge">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.min.js"></script>
<title>Document</title>
</head>
<body>
<script>
const config = {
type: Phaser.AUTO,width: 800,height: 600,parent: 'phaser-example',physics: {
default: 'arcade'
},scene: {
preload: preload,create: create,update: update
}
};
var debug;
var source;
var target = new Phaser.Math.Vector2();
var distanceText;
new Phaser.Game(config);
function preload ()
{
this.load.image('worm','assets/worm.png');
}
function create ()
{
source = this.physics.add.image(100,300,'worm');
debug = this.add.graphics();
this.input.on('pointerdown',function (pointer) {
target.x = pointer.x;
target.y = pointer.y;
this.physics.movetoObject(source,target,250);
},this);
distanceText = this.add.text(10,10,'Click to set target',{ fill: '#00ff00' });
}
function update ()
{
var distance = Phaser.Math.distance.Between(source.x,source.y,target.x,target.y);
if (source.body.speed > 0)
{
distanceText.setText('distância: ' + distance);
if (distance < 4)
{
source.body.reset(target.x,target.y);
}
}
}
</script>
</body>
</html>
就像我说的,我的电脑上的 url 或路径没有任何作用,我只想在没有那个绿色方块的情况下在屏幕上显示我的精灵播放器,我看到了另一个问题,但没有给我提供解决方案,我该怎么办?
解决方法
它似乎找不到要查找的图像,这意味着它不存在,或者更有可能在您提供的位置中不存在。
如果您从根目录提供此网页(也就是它在 http://localhost
或 http://127.0.0.1
上可见,那么您可以尝试简单地在路径前添加一个 /
,因此:/assets/worm.png
,前导 /
表示它将从您网页的根目录搜索资产。