首页 > 解决方案 > 移相器游戏不是工人阶级扩展问题

问题描述

我正在为一个项目设计,它对我的​​场景说这个,它只是一个白色的空白屏幕

当我检查调试时,我得到了这个:

Uncaught TypeError: Class extends value undefined is not a constructor or 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,
        width: 800,
        height: 600,
        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 上给出的概率

标签: htmlphaser-framework

解决方案


如果你打算为你的场景使用一个类,那么你需要改变你的游戏配置来反映这一点。目前它仍在使用旧的 3-function 方法,但您需要告诉它您现在使用的是 Scene 类:

scene: [ Boot ]

“引导”是您的引导场景。添加更多场景?将它们附加到此数组。列表中的第一个将自动启动。


推荐阅读