1
0

phaser_addon.js 579 B

1234567891011121314
  1. // add a button to a scene
  2. // similar to buttons in Phaser v2
  3. Phaser.Scene.prototype.addButton = function(x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)
  4. {
  5. // add a button
  6. var btn = this.add.sprite(x, y, key, outFrame).setInteractive();
  7. btn.on('pointerover', function (ptr, x, y) { this.setFrame(overFrame) } );
  8. btn.on('pointerout', function (ptr) { this.setFrame(outFrame) } );
  9. btn.on('pointerdown', function (ptr) { this.setScale(0.9, 0.9) } );
  10. btn.on('pointerup', callback.bind(callbackContext));
  11. return btn;
  12. };