Jump to content

Multi-hitbox Phaser Button


Recommended Posts

Hi all,


I am trying to extend the Phaser.Button to have different hit-areas depending on it's state:

this.onInputDown.add(() => {this._isDown = true;let tempPhaserFrame = game.cache.getFrameByName(key, frameDown);if (tempPhaserFrame instanceof Phaser.Frame) {this.hitArea = tempPhaserFrame.getRect();// this.hitArea.offset(-this.anchor.x * this.hitArea.width, -this.anchor.y * this.hitArea.height);console.log(this.hitArea);}});

However, when I do this the button immediately gets unpressed once the hitArea is changed. Why is this?

How could I achieve a variable sized button hit check?



Link to comment
Share on other sites

Hi Skeptron,


Not really, it is just that the when the button is pressed it reduces it's size visually. I wanted to represent that in the hit box, so that when you drag out the mouse while not releasing the button, it would pop-out (became unpressed) at the new smaller edge instead of the bigger original edge.


Does that make sense?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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