![](/img/trans.png)
[英]Phaser Animation isn't working and freezing my game, frames from sprite sheet don't seem to load
[英]Can't load a sprite in Phaser 3 game
我嘗試使用來自網絡的鏈接和 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 或 path 沒有任何作用,我只想在沒有那個綠色方塊的情況下在屏幕上顯示我的精靈播放器,我看到了另一個問題,但沒有給我提供解決方案,我該怎么辦?
它似乎找不到它要查找的圖像,這意味着它不存在,或者更有可能它不存在於您提供的位置。
如果您從根目錄提供此網頁(即它在http://localhost
或http://127.0.0.1
上可見,那么您可以嘗試在路徑前簡單地添加一個/
,例如: /assets/worm.png
,前導/
意味着它將從您網頁的根目錄搜索資產。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.