扩展移相器按钮类不工作

extending phaser button class not working

本文关键字:工作 按钮 扩展      更新时间:2023-09-26

我需要扩展phaser按钮类来创建新的按钮,但阶段中没有按钮,但控制台中没有错误这是我扩展类的代码

var GAME = GAME || {}; // game namespace 
GAME.UiButton = function(){ // game class for buttons
            Phaser.Button.call(this,game);
    };
    GAME.UiButton.prototype = Object.create(Phaser.Button.prototype);
    GAME.UiButton.constructor = Phaser.Button;
    //
    game.state.start("preloader");

然后当我创建新对象时,屏幕中没有按钮

var playButton = new GAME.UiButton(game,0,0,"button");

您的构造函数没有任何参数。

GAME.UiButton = function(game, x, y, key, etc...){ 
    Phaser.Button.call(this, game, x, y, key, etc...);
};

GAME.UiButton = function(){ 
    Phaser.Button.apply(this, arguments);
};

而且你永远不会在游戏中添加按钮。

game.add.existing(playButton)

DEMO