我无法使用 Phaser 3 中的创建功能将任何内容加载到 canvas
I cannot get anything to load onto the canvas with the create function in Phaser 3
我无法预加载图像
我试过将它转换为 url,我试过将其复制到项目文件夹中的文件,我试过只输入文件名。
function preload(){
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.spritesheet('dude', 'assets/dude.png');
this.load.image('star', 'assets/star.png');
} // preloads all of the files I will need to make the game
function create() {
this.add.sprite(200, 200, 'star');
} // applies the files
function update() {
}// update every frame
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#FF0000',
physics: {
default: 'arcade',
arcade: {
gravity: {y:200},
debug: false
}
},
scene: {
preload,
create,
update
},
} // configures the game
var game = new Phaser.Game(config);
我想在 canvas 上成功显示图像,但它只显示一个黑框,上面有一些绿线。非常感谢任何有关如何解决此问题或我遗漏的提示,谢谢。
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre><code> function preload() {
this.load.image('sky', 'file:///home/chronos/u-fc7808c01e889e74148d1013b69f0a2241def976/Downloads/testprogram-atom.js/assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.spritesheet('dude', 'assets/dude.png');
this.load.image('star', '/home/jojobinks/Desktop/testprogram-atom.js/star.png');
}
function create() {
this.add.image(0, 0, 'sky');
}
function update() {
}
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#FF0000',
physics: {
default: 'arcade',
arcade: {
gravity: {y:200},
debug: false
}
},
scene: {
preload,
create,
update
},
}
var game = new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser@3.16.2/dist/phaser-arcade-physics.min.js"></script>
我无法预加载图像
我试过将它转换为 url,我试过将其复制到项目文件夹中的文件,我试过只输入文件名。
function preload(){
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.spritesheet('dude', 'assets/dude.png');
this.load.image('star', 'assets/star.png');
} // preloads all of the files I will need to make the game
function create() {
this.add.sprite(200, 200, 'star');
} // applies the files
function update() {
}// update every frame
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#FF0000',
physics: {
default: 'arcade',
arcade: {
gravity: {y:200},
debug: false
}
},
scene: {
preload,
create,
update
},
} // configures the game
var game = new Phaser.Game(config);
我想在 canvas 上成功显示图像,但它只显示一个黑框,上面有一些绿线。非常感谢任何有关如何解决此问题或我遗漏的提示,谢谢。
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre><code> function preload() {
this.load.image('sky', 'file:///home/chronos/u-fc7808c01e889e74148d1013b69f0a2241def976/Downloads/testprogram-atom.js/assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.spritesheet('dude', 'assets/dude.png');
this.load.image('star', '/home/jojobinks/Desktop/testprogram-atom.js/star.png');
}
function create() {
this.add.image(0, 0, 'sky');
}
function update() {
}
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#FF0000',
physics: {
default: 'arcade',
arcade: {
gravity: {y:200},
debug: false
}
},
scene: {
preload,
create,
update
},
}
var game = new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser@3.16.2/dist/phaser-arcade-physics.min.js"></script>