Jump to content

Buttons only work at 0,0


Recommended Posts

Hi Everyone! I'm very new to Phaser and I'm struggling with one issue that I can't make sense of at all. I've created an extension of Phaser's button class which works really well. Only problem is (and this is the case for the standard Phaser button as well), is the button will work fine if it's set to 0,0 on the stage. But if I try to move the button at all, it's like the hit area doesn't stay with the actual button on screen. This is the case for both desktop (using Chrome) and on my Android phone. Has anyone seen this behavior before? I have no idea what to do about it and it's driving me nuts.

I'm using Phaser 2.10.1 with various states. Here's a look at what my button class looks like:


var GameButton = function (game, xPos, yPos, key, label, callback, callbackContext, overFrame, outFrame, downFrame, upFrame, group) {

    Phaser.Button.call(this, game, xPos, yPos, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame, group);

    this.anchor.setTo(0.5, 0.5);
    this.style = {font: '80px Rajdhani', fill: '#ffffff', fontWeight: 'bold'};
    this.labelText = new Phaser.Text(game, 0, 0, label, this.style);
    this.labelText.anchor.setTo(0.5, 0.5);

    console.log(this.width + '; ' + this.height);


GameButton.prototype = Object.create(Phaser.Button.prototype);
GameButton.prototype.constructor = Phaser.Button;

GameButton.prototype.setLabel = function(label) {

Link to comment
Share on other sites

Just an update on this. I was able to correct the issue by reverting to 2.6.2 (instead of 2.10.1). I'm not sure if I had to go that far back to address the issue, but after a TON of reading and trying things that's where I ended up. Hope this helps someone in the future!

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...