Taleforge Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
wayfinder Posted September 3, 2014 Share Posted September 3, 2014 You can load polygons made with PhysicsEditor for pixel-perfect click detection (see examples.phaser.io for how to use it). Phaser.Polygon does provide a function to tell you whether a given coordinate is inside it or not, iirc. Link to comment Share on other sites More sharing options...
Taleforge Posted September 5, 2014 Author Share Posted September 5, 2014 Ok so I guess there is no better way. I tryed that way, but i realized it is a bit more than just checking wheather the pointer is inside the poly or not. There could be a other sprite in front of my poly.Thanks for the help, i will try the polygon a bit more. Link to comment Share on other sites More sharing options...
Taleforge Posted September 6, 2014 Author Share Posted September 6, 2014 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 More sharing options...
Wavertron Posted September 6, 2014 Share Posted September 6, 2014 Question about the Polygon.contains() method, from the docs it takes an x and y param. If you pass it a sprite will it be checking against just the single xy position of the sprite? Cause that won't be enough for truly precise overlap checking. Link to comment Share on other sites More sharing options...
Taleforge Posted September 15, 2014 Author Share Posted September 15, 2014 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 More sharing options...
Recommended Posts