zgniatacz_galaktyk Posted November 11, 2015 Share Posted November 11, 2015 Hi, I am new to Pixi and have some questions about events. I have a bunch of sprites that are hexagonal tiles (not squares). I want to be able to handle mousover, mouse out and click events over these hexes. But the events are emited for the sprite rectangular areas, not the actual hexagonal shape. This question can be generalized: how to get all sorts of events (mousemove, mouse click etc.) only when a non-transparent pixel is clicked or hovered over. I thought I maybe could examine a texture pixel where the mouse currently is and check if the underlaying pixel is transparent but I don't know how to do this. Any ideas? Another question I have is about mosemove event. Suppose I have this code:mySprite.mousemove(mouseData){ // do something...}What happens is mousemove event is fired off even if the mouse moves outside of the sprite. It seems like this event is "global", so what's the point of handling this event for mySprite? I also noticed the documentation seems outdated. For example mouseData parameter description in the example above is incorrect (it doesn't have getLocalPosition function, instead there's data object that has more stuff). Other example is that sprite events are not in the official documentation at all Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 11, 2015 Share Posted November 11, 2015 Yes, interaction manager is a pain, and docs are outdated. You need to add hitArea to your objects, make one PIXI.Polygon and specify mySprite.hitArea = myPolygon whenever you create a tile. P.S. we even have a bounty on that thing: https://www.bountysource.com/issues/26281649-rewrite-interaction-manager Quote Link to comment Share on other sites More sharing options...
fire7side Posted February 23, 2016 Share Posted February 23, 2016 Why isn't there a hitArea property in the sprite class? Does this still work? How is it positioned? Quote Link to comment Share on other sites More sharing options...
fire7side Posted February 24, 2016 Share Posted February 24, 2016 OK, I think I get it. I use the Polygon.contains() method to check for the mouse position added to the sprite. I'll try that, anyway. Quote Link to comment Share on other sites More sharing options...
Hachi Posted February 28, 2016 Share Posted February 28, 2016 Just to mention on this subject. I am not all that knowledgeable on the inner workings of PIXI yet, but I have made my own workaround by using the InteractionManager, so I am willing to help and see the issue you have, if you need. I do event handling manually with eventlisteners on the canvas, but otherwise use the InteractionManager and hitArea to make the precise hit detection, you can find the codes around here: https://github.com/Hachitus/warmapengine/blob/master/src/components/map/core/ObjectManager.js and here: https://github.com/Hachitus/warmapengine/tree/master/src/components/map/extensions/hexagons . Though they might not be that clear as the project is quite modularized and fragmented. Quote Link to comment Share on other sites More sharing options...
fire7side Posted February 29, 2016 Share Posted February 29, 2016 I think I posted some on another thread, but Sprite has an undocumented member called hitArea which is a polygon graphic object. I just assigned a polygon that represented the area I wanted, and it worked perfectly. Everything outside the polygon is ignored by the interactive functions. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 29, 2016 Share Posted February 29, 2016 Why cant you use v3? What exactly is there in v2 that you cant port it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.