gabehollombe Posted May 31, 2014 Share Posted May 31, 2014 Hey folks! I'm working on creating a game that uses a hexagon grid as its board. I'd like to let players click/tap on a hexagon cell to select it. I can use drawPolygon() from a Geometry instance to get the hexagons drawn, but drawPolygon doesn't return anything I can attach an input handler event to? I know I can always translate pixel values into hexagons with an algorithm, but is there an easier way to detect which polygon I've clicked/touched? Link to comment Share on other sites More sharing options...
OpherV Posted May 31, 2014 Share Posted May 31, 2014 You can use P2 physics and create a hexagon polygon body to go along with your hexagon sprite, then detect clicks on the body: http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=body+click.js&t=body%20click Link to comment Share on other sites More sharing options...
gabehollombe Posted June 1, 2014 Author Share Posted June 1, 2014 Thanks, @OpherV. That's a good idea. But I'm thinking that since I don't need a physics engine (I'm just interested in click detection), perhaps I'm better off with just doing the pixel coordinate translation myself. Link to comment Share on other sites More sharing options...
gabehollombe Posted June 1, 2014 Author Share Posted June 1, 2014 Hey folks! I'm working on creating a game that uses a hexagon grid as its board. I'd like to let players click/tap on a hexagon cell to select it. I can use drawPolygon() from a Geometry instance to get the hexagons drawn, but drawPolygon doesn't return anything I can attach an input handler event to? I know I can always translate pixel values into hexagons with an algorithm, but is there an easier way to detect which polygon I've clicked/touched? It looks like PIXI has support for clicking on DisplayObjects, which I'm guessing Graphics is an instance of... Has anyone figured out how to use a PIXI InteractionManager with a Phaser Graphics object instance to handle clicks? Link to comment Share on other sites More sharing options...
OpherV Posted June 7, 2014 Share Posted June 7, 2014 Did you try setting up hitArea?http://www.goodboydigital.com/pixijs/docs/classes/DisplayObjectContainer.html#property_hitArea Link to comment Share on other sites More sharing options...
gabehollombe Posted June 14, 2014 Author Share Posted June 14, 2014 Did you try setting up hitArea?http://www.goodboydigital.com/pixijs/docs/classes/DisplayObjectContainer.html#property_hitAreaYou know, I saw this, but I wasn't able to find an example showing how to manually set up a hitArea and touch detection here. Can you point me at any existing examples of this? Link to comment Share on other sites More sharing options...
Recommended Posts