Skip to content

Commit 4e10a86

Browse files
fix: handle spine with .json, fix spine pivot problem
1 parent 3534bdd commit 4e10a86

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,17 +610,19 @@ export default class PixiStage {
610610
setTimeout(() => {
611611
if (spineResource && this.getStageObjByUuid(figureUuid)) {
612612
const figureSpine = new Spine(spineResource.spineData);
613-
const transY = spineResource?.spineData?.y ?? 0;
613+
const spineBounds = figureSpine.getLocalBounds();
614+
const spineCenterX = spineBounds.x + spineBounds.width / 2;
615+
const spineCenterY = spineBounds.y + spineBounds.height / 2;
616+
figureSpine.pivot.set(spineCenterX, spineCenterY);
617+
// TODO: set animation 还没做
618+
// figureSpine.state.setAnimation()
614619
/**
615620
* 重设大小
616621
*/
617622
const originalWidth = figureSpine.width;
618623
const originalHeight = figureSpine.height;
619624
const scaleX = this.stageWidth / originalWidth;
620625
const scaleY = this.stageHeight / originalHeight;
621-
// 我也不知道为什么啊啊啊啊
622-
figureSpine.y = -(scaleY * transY) / 2;
623-
figureSpine.state.setAnimation(0, '07', true);
624626
const targetScale = Math.min(scaleX, scaleY);
625627
const figureSprite = new PIXI.Sprite();
626628
figureSprite.addChild(figureSpine);

packages/webgal/src/Stage/MainStage/useSetFigure.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,12 @@ function removeFig(figObj: IStageObject, enterTikerKey: string, effects: IEffect
207207

208208
function addFigure(type?: 'image' | 'live2D' | 'spine', ...args: any[]) {
209209
const url = args[1];
210+
const baseUrl = window.location.origin;
211+
const urlObject = new URL(url, baseUrl);
212+
const _type = urlObject.searchParams.get('type') as 'image' | 'live2D' | 'spine' | null;
210213
if (url.endsWith('.json')) {
211214
return addLive2dFigure(...args);
212-
} else if (url.endsWith('.skel')) {
215+
} else if (url.endsWith('.skel') || _type === 'spine') {
213216
// @ts-ignore
214217
return WebGAL.gameplay.pixiStage?.addSpineFigure(...args);
215218
} else {

0 commit comments

Comments
 (0)