问题描述
嘿,我一直在尝试在画布中输入乐谱文本,但给了我这个错误:未捕获的类型错误:无法读取未定义的属性“容器”。
代码如下:
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,"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,但我不知道为什么不能识别容器类,任何人都可以帮助我?
解决方法
至少在您的示例代码中,您有一个错字。应该是Phaser.GameObjects.Container
而不是Phaser.GameObjets.Container