Skip to content

Commit 26f8b05

Browse files
committed
[ts][pixi] Fixed regression that caused multiple animatino update at window resize.
1 parent 3ef197b commit 26f8b05

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

spine-ts/spine-pixi/src/Spine.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ export class Spine extends Container {
123123
}
124124
/** When `true`, the Spine AnimationState and the Skeleton will be automatically updated using the {@link Ticker.shared} instance. */
125125
public set autoUpdate (value: boolean) {
126-
if (value) this.autoUpdateWarned = false;
126+
if (value) {
127+
Ticker.shared.add(this.internalUpdate, this);
128+
this.autoUpdateWarned = false;
129+
} else {
130+
Ticker.shared.remove(this.internalUpdate, this);
131+
}
127132
this._autoUpdate = value;
128133
}
129134

@@ -166,14 +171,14 @@ export class Spine extends Container {
166171

167172
/** If {@link Spine.autoUpdate} is `false`, this method allows to update the AnimationState and the Skeleton with the given delta. */
168173
public update (deltaSeconds: number): void {
169-
if (this._autoUpdate && !this.autoUpdateWarned) {
174+
if (this.autoUpdate && !this.autoUpdateWarned) {
170175
console.warn("You are calling update on a Spine instance that has autoUpdate set to true. This is probably not what you want.");
171176
this.autoUpdateWarned = true;
172177
}
173-
this.internalUpdate(deltaSeconds);
178+
this.internalUpdate(0, deltaSeconds);
174179
}
175180

176-
protected internalUpdate (deltaSeconds?: number): void {
181+
protected internalUpdate (_deltaFrame: number, deltaSeconds?: number): void {
177182
// Because reasons, pixi uses deltaFrames at 60fps. We ignore the default deltaFrames and use the deltaSeconds from pixi ticker.
178183
const delta = deltaSeconds ?? Ticker.shared.deltaMS / 1000;
179184
this.state.update(delta);
@@ -186,7 +191,6 @@ export class Spine extends Container {
186191

187192
/** Render the meshes based on the current skeleton state, render debug information, then call {@link Container.updateTransform}. */
188193
public override updateTransform (): void {
189-
if (this._autoUpdate) this.internalUpdate();
190194
this.renderMeshes();
191195
this.sortChildren();
192196
this.debug?.renderDebug(this);

0 commit comments

Comments
 (0)