AFAIK класс кнопок, как в Phaser v2, отсутствует в Phaser3 по неизвестным причинам.В моей Phaser3 примере игры на github я добавил addButton
прототип к Scene
, чтобы иметь возможность снова использовать кнопки.
См. Код ниже:
// include code below in separate .js file
// add a button to a scene
Phaser.Scene.prototype.addButton = function(x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)
{
// add a button
var btn = this.add.sprite(x, y, key, outFrame).setInteractive();
btn.on('pointerover', function (ptr, x, y) { this.setFrame(overFrame) } );
btn.on('pointerout', function (ptr) { this.setFrame(outFrame) } );
btn.on('pointerdown', function (ptr) { this.setScale(0.9, 0.9) } );
btn.on('pointerup', callback.bind(callbackContext));
return btn;
};
// in a scene you can then do this
var mybutton = this.addButton(100, 100, 'mysprites', this.doButtonAction, this, 'btn_play_hl', 'btn_play', 'btn_play_hl', 'btn_play');