Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Polygon with input-events and overlap


Taleforge
 Share

Recommended Posts

Hi,

 

i want to have some polygon-like shape that can handle overlaps and input-events.

Is there any element like that in Phaser?

 

I dont want to use physics - since there is no real use for that in my game.

 

My first attempt was to use the Phaser.Polygon, but than i would have to create the input events and overlap-checks all by myself.

The second try was to use a Phaser.Graphics without drawing a fill or line. But there seem to be no overlap or input-events.

My last idea was to use a Phaser.Sprite with a hitArea, the hitArea would handle the input-events but how could I do the overlap checks than?

 

Is there any Phaser-element for this use-case? What is the best practise?

 

Thanks for any help,

 

Taleforge

Link to comment
Share on other sites

For anyone interested in this:
 

my final solution was to create a empty sprite (by passing no image to the Sprite contructor) and than setting a Phaser.Polygon on the sprite.hitArea. That solves the input events.

For the overlap or "enter"-check I call the following:

sprite.hitArea.contains(thePlayerSprite)

I guess this method even works with other geometics like circle or rectangle.

 

Thanks again to wayfinder for the hint on the contains-method!

Link to comment
Share on other sites

  • 2 weeks later...

That is true, it will just check the x and y.

In my case it is enough, because I just want to know "Is the player standing within the polygon" or "is the input within the polygon?".

For a real overlap you would have to check the width, height, scaling and the anchor (maybe i forgot something?).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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