Skip to content

Commit b1f5018

Browse files
committed
fix: correct pivot point and positioning for Live2D figure
1 parent 09459d5 commit b1f5018

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

packages/webgal/src/Core/controller/stage/pixi/PixiController.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ export default class PixiStage {
625625
thisFigureContainer.zIndex = metadata.zIndex;
626626
}
627627
}
628+
629+
thisFigureContainer.pivot.set(0, this.stageHeight / 2);
630+
628631
// 挂载
629632
this.figureContainer.addChild(thisFigureContainer);
630633
this.figureObjects.push({
@@ -668,16 +671,26 @@ export default class PixiStage {
668671

669672
model.scale.set(targetScale);
670673
model.anchor.set(0.5);
671-
model.position.x = stageWidth / 2;
672-
model.position.y = stageHeight / 1.2;
673674

674-
if (pos === 'left') {
675-
model.position.x = targetWidth / 2;
675+
const targetHeight = model.height * targetScale;
676+
677+
let baseY = stageHeight / 2;
678+
if (targetHeight < stageHeight) {
679+
baseY = stageHeight / 2 + (stageHeight - targetHeight) / 2;
676680
}
677-
if (pos === 'right') {
678-
model.position.x = stageWidth - targetWidth / 2;
681+
thisFigureContainer.setBaseY(baseY);
682+
683+
if (pos === 'center') {
684+
thisFigureContainer.setBaseX(stageWidth / 2);
685+
} else if (pos === 'left') {
686+
thisFigureContainer.setBaseX(targetWidth / 2);
687+
} else if (pos === 'right') {
688+
thisFigureContainer.setBaseX(stageWidth - targetWidth / 2);
679689
}
680690

691+
model.position.x = 0;
692+
model.position.y = stageHeight / 1.2;
693+
681694
let motionToSet = motion;
682695
let animation_index = 0;
683696
let priority_number = 3;

0 commit comments

Comments
 (0)