admin管理员组文章数量:1391995
I am trying to build a small game using Phaser, but I am stuck at the basics. I want to make a picture the background of my entire game, but it does not work, the console does not give me any errors the background just doesn't change, here is my javascript:
var config = {
type: Phaser.AUTO,
width: 600,
height: 800,
physics: {
default: 'arcade',
arcade: {
gravity: {y: 500},
debug: false
}
},
};
var game = new Phaser.Game(config);
function preload() {
this.load.image('background', './star-background.jpg');
}
function create() {
this.add.image(400, 300, 'background');
}
function update() {
}
What am I missing and how can I make a picture the background of the game?
I am trying to build a small game using Phaser, but I am stuck at the basics. I want to make a picture the background of my entire game, but it does not work, the console does not give me any errors the background just doesn't change, here is my javascript:
var config = {
type: Phaser.AUTO,
width: 600,
height: 800,
physics: {
default: 'arcade',
arcade: {
gravity: {y: 500},
debug: false
}
},
};
var game = new Phaser.Game(config);
function preload() {
this.load.image('background', './star-background.jpg');
}
function create() {
this.add.image(400, 300, 'background');
}
function update() {
}
What am I missing and how can I make a picture the background of the game?
Share Improve this question asked Jan 24, 2019 at 10:54 Murray JohnsonMurray Johnson 3111 gold badge4 silver badges15 bronze badges1 Answer
Reset to default 3Your config object is missing the scene
items. This is necessary to tell Phaser to add the scene(s) to the game. See the documentation here.
Give this a try:
var config = {
type: Phaser.AUTO,
width: 600,
height: 800,
physics: {
default: 'arcade',
arcade: {
gravity: {y: 500},
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
That should load your first scene with the functions you have created. Otherwise, your image setup looks great. I highly remend following along with the official tutorial Making your first Phaser 3 game to get the basics figured out. Great explanations and examples of a typical game setup.
本文标签: javascriptHow to set a background image to a Phaserjs gameStack Overflow
版权声明:本文标题:javascript - How to set a background image to a Phaser.js game? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744775135a2624578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论