javascript - 为什么图像没有在 Phaser 中加载?
问题描述
我正在关注本教程 ,我按照说明做了所有事情,但是我的图像没有加载,我得到了这个:
我的代码:
主.js:
/** @type{import{"../libs/phaser"}} */
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: {
preload: preload,
create: create,
update: update
}
};
function preload ()
{
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.image('star', 'assets/star.png');
this.load.image('bomb', 'assets/bomb.png');
this.load.spritesheet('dude',
'assets/dude.png',
{ frameWidth: 32, frameHeight: 48 }
);
}
function create ()
{
this.add.image(400, 300, 'sky');
this.add.image(400, 300, 'star');
}
function update ()
{
}
var game = new Phaser.Game(config);
game.state.add('GameState',GameState);
game.state.start('GameState')
索引.html:
<!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">
<title>Document</title>
</head>
<body>
<script src="./libs/phaser.js"></script>
<script src="main.js"></script>
</body>
</html>
我的项目结构:
我试过的东西:
- 在 chrome/edge/firefox 上运行
- 将 .png 移出文件夹
我想这不是代码的问题,所以我不知道它在哪里以及如何解决它。这是我的错误:
解决方案
推荐阅读
- python - 我如何在 Python 中一遍又一遍地向数字添加一些东西
- java - Java:插入异常时如何传播“方法退出”?
- java - 如何将 lambda 表达式转换为普通代码?C#
- html - 如何为此创建脚本?
- python - 在 python heroku 部署期间无法安装依赖项
- python - 从 2D numpy 数组中删除特定行值数组的快速方法
- java - Mac JAVA 上不显示窗口
- r - 通过每次添加固定值来创建重复的值范围
- typescript - knexjs innerjoin 返回列
- c# - C# - 使用 GroupBy 的 LINQ Lambda 表达式 - 为什么嵌套验证效率如此低下?