Jump to content

Multi-hitbox Phaser Button


jorge.graca
 Share

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?

 

Thanks.

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

 Share

  • Recently Browsing   0 members

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