Here, I am gonna share my hittest utililty class for SkeletonSprite (SpriteAnimation).
Official spine-starling libraly doesn't offer hittest method with SkeletonSprite inner parts, but there are a lot of situations we wanna do hittest with inner parts of SkeletonSprite, which are Region Attachments(images), Mesh Attachments or free polygons. So I made hittest utililty.
Touch parts below to control funny character.
Body : Boundingbox(=Polygon) Attachent
Eyes : Boundingbox(=Polygon) Attachent
Arms : Region(=Image) Attachent
Ribbon : Mesh Attachent
// in global axis var posGrobal:Point = new Point(100, 100); var isHit:Boolean = SpineHitTestUtil.hitTestWithAttachmentByGlobalPoint(skeletonSprite, "slotName", posGrobal); // in local axis var posSpriteLocal:Point = new Point(10,10); var isHit:Boolean = SpineHitTestUtil.hitTestWithAttachmentByLocalPoint(skeletonSprite, "slotName", posSpriteLocal);
Hittest is available with 4 kinds of attachments.
1) Region Attachment (= quad image)
2) BoundingBox Attachment (= free polygon)
3) Mesh Attachment
4) Linked Mesh Attachment
Using Crossing Number Algorithm, hittest calculation with Region or BoundingBox Attachment is accurate.
With Mesh Attachments, calculation is rough but enough in usual becasue you can use BoundingBox Attachment instead for hittest.
NOTE: bounding boxes means polygons in Spine. See http://esotericsoftware.com/spine-bounding-boxes .
>The term "bounding box" is somewhat of a misnomer. Technically a bounding box is the smallest rectangle that contains an object. In Spine, bounding boxes are actually arbitrary polygons, though they are often used to define the bounds of the skeleton for hit detection or physics purposes.
Tuto page (in Japanese) here.
I hope someone likes the utililty class.