Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
fix slot misalignment on first frame
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed Jun 6, 2024
1 parent 744da1f commit 619a9c4
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/Spine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class Spine extends Container implements View

this.transformAttachments();

this.updateSlotAttachments();
this.updateSlotObjects();
}

private validateAttachments()
Expand Down Expand Up @@ -505,29 +505,34 @@ export class Spine extends Container implements View
* ensure that attached containers map correctly to their slots
* along with their position, rotation, scale, and visibility.
*/
private updateSlotAttachments()
private updateSlotObjects()
{
for (const i in this._slotsObject)
{
const slotAttachment = this._slotsObject[i];

if (!slotAttachment) continue;

const { slot, container } = slotAttachment;
this.updateSlotObject(slotAttachment);
}
}

container.visible = this.skeleton.drawOrder.includes(slot);
private updateSlotObject(slotAttachment: {slot:Slot, container:Container})
{
const { slot, container } = slotAttachment;

if (container.visible)
{
const bone = slot.bone;
container.visible = this.skeleton.drawOrder.includes(slot);

container.position.set(bone.worldX, bone.worldY);
if (container.visible)
{
const bone = slot.bone;

container.scale.x = bone.getWorldScaleX();
container.scale.y = bone.getWorldScaleY();
container.position.set(bone.worldX, bone.worldY);

container.rotation = bone.getWorldRotationX() * DEG_TO_RAD;
}
container.scale.x = bone.getWorldScaleX();
container.scale.y = bone.getWorldScaleY();

container.rotation = bone.getWorldRotationX() * DEG_TO_RAD;
}
}

Expand Down Expand Up @@ -622,18 +627,12 @@ export class Spine extends Container implements View
// TODO only add once??
this.addChild(container);

// TODO search for copies... - one container - to one bone!
this._slotsObject[slot.data.name] = {
container,
slot
};

const renderGroup = this.renderGroup || this.parentRenderGroup;

if (renderGroup)
{
renderGroup.structureDidChange = true;
}
this.updateSlotObject(this._slotsObject[slot.data.name]);
}

/**
Expand Down

0 comments on commit 619a9c4

Please sign in to comment.