首页 > 解决方案 > 为什么我在 Phaser 中的游戏无法识别 Phaser.GameObjets.Container?

问题描述

嘿,我一直在尝试在画布中输入乐谱文本,但给了我这个错误:未捕获的类型错误:无法读取未定义的属性“容器”。

这是代码:

class ScoreBox extends Phaser.GameObjets.Container{
    constructor (config){
    //invoke constructor of extended class
        super (config.scene);
    //get scene from parameter and set scene atribute
        this.scene = config.scene;
    //add a text box to the scene
        this.text = this.scene.add.text ( 0, 0, "SCORE: 0");
    //set text origin
        this.text.setOrigin (0.5, 0.5);
    //add the text to the container
        this.add (this.text);
    //add the container to the scene
        this.scene.add.existing (this);
    //Enable score update through emitter
        emitter.on (messageConstants.SCORE_UPDATED, this.scoreUpdated);
    }
    scoreUpdated (){
        this.text.setText ("SCORE: " + model.score);
    }
    
}

我将它连接到 html 但我不知道为什么不识别容器类,任何人都可以帮助我吗?

标签: containersphaser-framework

解决方案


至少在您的示例代码中,您有一个错字。应该Phaser.GameObjects.Container不是Phaser.GameObjets.Container


推荐阅读