I have a question about detecting touches on various parts of the skeleton in the Corona Runtime. I have seen this post in the forum: [Corona/lua] get attachment/slot for click/touch events. I understand that it's no longer trivial for performance reasons to add a touch listener in Corona directly to an attachment to a slot. So I've tried adding display objects on top of the skeleton (as suggested in that old post), and this seems to almost work
but I can't figure out how to line the boxes up perfectly with the slots. Here's a video of what I've got so far:
https://drive.google.com/file/d/17PbDmZ_6NCdq8NU3RVTIalN0q4qzztxl/view?usp=sharing
As you can see, the boxes seem to be centered around the joint of the bone/lot
which is good
but they're not pivoting the same way the attachments do. That is to say, the arm's bounding box is centered around the cat's shoulder, instead of the middle of the arm, where it should be. Another example is the cat's body. The big box, for the cat's body, needs to be offset by half its height, so that it's perfectly over that body part. I'd like to get this right, so I can use it in gameplay, but I'm not sure how to correct it. I've tried adjusting the local y positions and anchors of my collision boxes, but to no avail. My current approach is to create the white collision boxes like this:
local slot = cat.skeleton:findSlot(name)
local w, h = slot.attachment.width, slot.attachment.height
local w, h = slot.attachment.width, slot.attachment.height
local collider = display.newRect(0,0,w, h)
cat:insert(collider)
And then just assign them positions every frame, like so:
local bone = cat.skeleton:findBone(name)
local collider = cat.boneColliderGroups[name]
collider.x = bone.worldX
collider.y = bone.worldY
collider.rotation = -bone.rotation
But there's clearly something I'm missing. Is this the preferred method for getting a touch listener on each part of the animation? Is there a code sample somewhere? I hope so!