问题描述
我正在为一个项目进行设计,它是对我的场景说的,它只是一个空白的白色屏幕
当我检查调试时,我得到了:
未捕获的TypeError:类扩展未定义的值不是构造函数或null
这是我的索引文件
<!doctype html>
<html lang="en">
<head>
<title>save the mahanadi river,an energy project</title>
<!--libs-->
<script src="//cdn.jsdelivr.net/npm/phaser@3.24.1/dist/phaser.js"></script>
<!--project-->
<script type = "text/javascript" src = ".js/game.js"></script>
<!--scenes-->
<script type = "text/javascript" src = "scenes/boot.js"></script>
<script type = "text/javascript" src = "scenes/menu.js"></script>
</head>
<body>
<H1>hello for now</H1>
</body>
</html>
和我的场景概率代码
class Boot extends Phaser.scene {
constructor() {
super("Boot")
};
preload (){
};
create (){
this.add.text(20,20,"welcome!")
};
update (){
};
};
这是我的game.js
window.onload = function(){
var config = {
type: Phaser.AUTO,width: 800,height: 600,physics: {
default: 'arcade',arcade: {
gravity: { y: 300 },debug: false
}
},scene: {
preload: preload,create: create,update: update
}
};
var game = new Phaser.Game(config);
}
ok thanks photon storm but i still have bugs
my game.js
window.onload = function(){
var config = {
type: Phaser.AUTO,Scenes: [Boot,Menu],Scenes.push(Boot),Scenes.push(Menu),physics: {
default: 'arcade',arcade: {
gravity: { y: 300 },debug: false
}
},};
var game = new Phaser.Game(config);
}
在phaser.push中提供概率的概率
解决方法
如果要为场景使用类,则需要更改游戏配置以反映这一点。目前,它仍然使用旧的三功能方法,但是您需要告诉它您现在正在使用Scene类:
scene: [ Boot ]
其中“引导”是您的引导场景。添加更多场景?将它们附加到此数组。列表中的第一个自动启动。