我刚刚创建了简单的index.html文件:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.20.1/dist/phaser-arcade-physics.min.js"></script>
<title>Document</title>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
还有index.js:
const config = {
...
};
const game = new Phaser.Game(config);
function preload() {
this.load.image("back","./assets/bg.jpg");
}
function create() {
this.add.image(400,300,"back");
}
但是由于CORS错误,我无法加载图像:
phaser-arcade-physics.min.js:1 access to XMLHttpRequest at 'file:///C:/Users/bruce/Documents/dev/flappy/assets/bg.jpg' from origin 'null' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes: http,data,chrome,chrome-extension,https.