I would like to parent a sprite to a bone.
Vanity items that are loaded on the fly, they don't have an attachment slot.
So I was hoping to just parent a sprite to a bone.
But I am failing hard. I can get the data of a bone, but that is just the local position and doesn't include the animation, since it's animated higher in hierarchy.
Long story short, how would I go about parenting a sprite to a bone?
Thanks heaps in advance.
Update: This returns me the WorldX, which I read about and was wondering where it is:
fighter.spineData.findBone("head")
However, once I move it into a variable like so
test = fighter.spineData.findBone("head")
Most of the attributes disappear.
I made it this far, but it just is close, and not exact
// my external data I send
constraint.offsets = {"scale": 0.8, "rotation": 0, "length": 130, "x": 0, "y": 0};
// get bone data
let x = lFighter.skeleton.findBone("head").worldX + lFighter.x;
let y = lFighter.skeleton.findBone("head").worldY + lFighter.y;
let rotation = (lFighter.skeleton.findBone("head").rotation) / 180 * 2*Math.PI;
// set new position
x = x - (constraint.offsets.length * 2 * Math.sin(rotation));
y = y - (constraint.offsets.length * 2 * Math.cos(rotation));
// apply offsets
x = x + constraint.offsets.x;
y = y + constraint.offsets.y;
constraint.child.x = x;
constraint.child.y = y;
constraint.child.rotation = -rotation + (constraint.offsets.rotation / 180 * 2*Math.PI);
if (debugMode) {
let graphics = new PIXI.Graphics();
graphics.beginFill(0x00ff30, 1);
graphics.drawRect(x, y, 10, 10);
gameScene.stage.addChild(graphics);
setTimeout(() => {
graphics.clear();
graphics.destroy();
}, 20);
}
Adding a new slot programatically, this seems the best solution.