Search code examples
collision-detectionkineticjs

KineticJS Hit Region To Image Collision Detection


Is there any way to detect whether a shape or point is in the image hit region? The event handling 'on' function seems to only deal with mouse/touch events.

If there isn't, then what would be the best way of getting collision boundaries on a map. The way I was planning on doing it, was to have the map and a wallMap underneath it, creating a hit region with the wallMap and detecting whether the character had hit it.


Solution

  • yep, just use the getPointerPosition() method to get the mouse/touch position, and then use the intersects() method to test for an intersection:

    http://kineticjs.com/docs/Kinetic.Stage.html#getpointerposition http://kineticjs.com/docs/Kinetic.Shape.html#intersects