瀏覽代碼

[ts][pixi] Add before/afterUpdateWorldTransforms to inject easily logic in skeleton lifecycle

Davide Tantillo 1 年之前
父節點
當前提交
17da13d432
共有 2 個文件被更改,包括 8 次插入6 次删除
  1. 3 6
      spine-ts/spine-pixi/example/control-bones-example.html
  2. 5 0
      spine-ts/spine-pixi/src/Spine.ts

+ 3 - 6
spine-ts/spine-pixi/example/control-bones-example.html

@@ -46,7 +46,6 @@
 
 
         // Create the spine display object
         // Create the spine display object
         const stretchyman = spine.Spine.from("stretchymanData", "stretchymanAtlas", { 
         const stretchyman = spine.Spine.from("stretchymanData", "stretchymanAtlas", { 
-          autoUpdate: false,
           scale: 0.75,
           scale: 0.75,
          });
          });
 
 
@@ -92,8 +91,8 @@
           })
           })
         }
         }
 
 
-        PIXI.Ticker.shared.add(() => {
-          const point = { x: 0, y: 0 };
+        const point = { x: 0, y: 0 };
+        stretchyman.beforeUpdateWorldTransforms = () => {
           for (let { bone, control } of controlBones) {
           for (let { bone, control } of controlBones) {
             point.x = control.x;
             point.x = control.x;
             point.y = control.y;
             point.y = control.y;
@@ -101,9 +100,7 @@
             bone.x = point.x;
             bone.x = point.x;
             bone.y = point.y;
             bone.y = point.y;
           }
           }
-          stretchyman.update(PIXI.Ticker.shared.deltaMS / 1000);
-        })
-        
+        };
       })();
       })();
     </script>
     </script>
   </body>
   </body>

+ 5 - 0
spine-ts/spine-pixi/src/Spine.ts

@@ -112,6 +112,9 @@ export class Spine extends Container {
 
 
 	protected slotMeshFactory: () => ISlotMesh = () => new SlotMesh();
 	protected slotMeshFactory: () => ISlotMesh = () => new SlotMesh();
 
 
+	beforeUpdateWorldTransforms: (object: Spine) => void = () => { };
+	afterUpdateWorldTransforms: (object: Spine) => void = () => { };
+
 	private autoUpdateWarned: boolean = false;
 	private autoUpdateWarned: boolean = false;
 	private _autoUpdate: boolean = true;
 	private _autoUpdate: boolean = true;
 	public get autoUpdate (): boolean {
 	public get autoUpdate (): boolean {
@@ -179,8 +182,10 @@ export class Spine extends Container {
 		const delta = deltaSeconds ?? Ticker.shared.deltaMS / 1000;
 		const delta = deltaSeconds ?? Ticker.shared.deltaMS / 1000;
 		this.state.update(delta);
 		this.state.update(delta);
 		this.state.apply(this.skeleton);
 		this.state.apply(this.skeleton);
+		this.beforeUpdateWorldTransforms(this);
 		this.skeleton.update(delta);
 		this.skeleton.update(delta);
 		this.skeleton.updateWorldTransform(Physics.update);
 		this.skeleton.updateWorldTransform(Physics.update);
+		this.afterUpdateWorldTransforms(this);
 	}
 	}
 
 
 	/** Render the meshes based on the current skeleton state, render debug information, then call {@link Container.updateTransform}. */
 	/** Render the meshes based on the current skeleton state, render debug information, then call {@link Container.updateTransform}. */