In Corona, a Skeleton has a group itself (skeleton.group). You can either specify a group of your own the skeleton will "draw" to, or let the skeleton create a group itself. Both things are accomplished via the spine.Skeleton.new() function, which takes skeleton data and an additional group.
The skeleton will then add subgroups to its "root" group every time you call Skeleton:updateWorldTransform. Each of these sub groups contains the mesh for one or more attachments (attachments are merged into a single mesh if they share the same image and blending state).
To achieve what you want, you can do the following.
- Disable the slot you want to manually replace with your own display group or sprite by setting its attachment to nil. This is optional if your display group or Sprite is big enough to overdraw the slot image completely. It will give you a tiny little bit more performance, since you don't draw something that will be overdrawn later.
local headSlot = skeleton:findSlot("head")
headSlot:setAttachment(nil)
- Apply your animation and update the skeleton world transforms, so the positions, rotations and scales of every bone in the skeleton are up to date, and the skeleton.group is filled with sub groups containing the currently visible attachments. Then get the bone you want to attach your group/sprite to and update the group's/sprite's position and rotation accordingly.
---
Update the transform of each bone based on the animation, as usual
animationState:update(delta)
animationState:apply(skeleton)
skeleton:updateWorldTransform()
---
Fetch the bone (not slot from the bone!) that you want to attach the group/sprite to
local bone = skeleton:findBone("headBone")
---
Set the position of your group/sprite to the bone's position, which is relative to the skeleton.group
---
circle was previously created with display.newCircle(0, 0, 20). We remove the circle and reinsert
---
it in the skeleton.group to make sure it's on top of all other skeleton attachments!
circle:removeSelf()
circle.x = bone.worldX
circle.y = bone.worldY
circle.rotation = bone:getWorldRotationY()
skeleton.group:insert(circle)
And that's it!
Note that an animation you apply may set the attachment on the slot you nil'ed earlier. The attachment on the slot will also be set when you reset the skeleton to the setup pose. In that case you have to reapply step 1 so the slot (and its currently active attachment) is "invisible" again.