Javascript 此.add.image不是带相位器3-3.16的功能

Javascript 此.add.image不是带相位器3-3.16的功能,javascript,function,phaser-framework,Javascript,Function,Phaser Framework,我正在尝试向标题屏幕添加一个按钮,我得到了这个。add.image不是一个函数 我已经把这个形象换成了其他的措辞,其他什么也没发生。我正在使用Zenva's academy,并跟随教程,遇到了这个问题 这是我的密码 class UiButton extends Phaser.GameObjects.Container { constructor(scene, x, y, key, hoverKey, text, targetCallback){ super(scene,

我正在尝试向标题屏幕添加一个按钮,我得到了这个。add.image不是一个函数

我已经把这个形象换成了其他的措辞,其他什么也没发生。我正在使用Zenva's academy,并跟随教程,遇到了这个问题

这是我的密码

class UiButton extends Phaser.GameObjects.Container {
    constructor(scene, x, y, key, hoverKey, text, targetCallback){
        super(scene, x, y);
        this.scene = scene; // the scene this container will be added to
        this.x = x; // x pos
        this.y = y; // y pos
        this.key = key; // BG image of button
        this.hoverKey = hoverKey; // image displays when hovered
        this.text = text; // text displayed on button
        this.targetCallback = targetCallback; // the callback function that will be called when clicked
    
        this.createButton(); // Creates UI Button
        this.scene.add.existing(this); // adds this container to our Phaser Scene
    }

    createButton() {
        //create Play Game Button
        this.button = this.add.image(0, 0, "button1");
        
        //make button interactive
        this.button.setInteractive();

        //scale the button
        this.button.setScale(1.4);


        //create button text
        this.buttonText = this.add.text(0, 0, this.text, {fontSize: "26px", fill: "#fff"});
        //center text in ui button
        Phaser.Display.Align.In.Center(this.buttonText, this.button);

        //add the two game objects to container
        this.add(this.button);
        this.add(this.buttonText);

        //Listen for events
        this.button.on("pointerdown", () => {
            this.targetCallback();
        });

        this.button.on("pointerover", () => {
            this.button.setTexture(this.hoverKey);
        });
        
        this.button.on("pointerout", () => {
            this.button.setTexture(this.key);
        });
        

    }
}
有什么想法吗


谢谢

容器对象有一个
add(child)
方法。但是它需要一个现有的游戏对象。我认为您正在尝试构建图像,需要使用场景(场景中的工厂)来实现这一点。因此,您应该尝试:

this.button = this.scene.add.image(0, 0, "button1");
案文也是如此:

this.buttonText = this.scene.add.text(0, 0, this.text, {fontSize: "26px", fill: "#fff"});

容器对象有一个
add(child)
方法。但是它需要一个现有的游戏对象。我认为您正在尝试构建图像,需要使用场景(场景中的工厂)来实现这一点。因此,您应该尝试:

this.button = this.scene.add.image(0, 0, "button1");
案文也是如此:

this.buttonText = this.scene.add.text(0, 0, this.text, {fontSize: "26px", fill: "#fff"});