, alpha: number, blend: MixBlend, direction: MixDirection) {
-
- let constraint: PhysicsConstraint | undefined;
- if (this.constraintIndex != -1) {
- constraint = skeleton.physicsConstraints[this.constraintIndex];
- if (!constraint.active) return;
- }
-
- const frames = this.frames;
-
- if (lastTime > time) { // Apply after lastTime for looped animations.
- this.apply(skeleton, lastTime, Number.MAX_VALUE, [], alpha, blend, direction);
- lastTime = -1;
- } else if (lastTime >= frames[frames.length - 1]) // Last time is after last frame.
- return;
- if (time < frames[0]) return;
-
- if (lastTime < frames[0] || time >= frames[Timeline.search1(frames, lastTime) + 1]) {
- if (constraint != null)
- constraint.reset();
- else {
- for (const constraint of skeleton.physicsConstraints) {
- if (constraint.active) constraint.reset();
- }
+ if (lastTime < frames[0] || time >= frames[Timeline.search1(frames, lastTime) + 1]) {
+ if (constraint != null)
+ constraint.reset();
+ else {
+ for (const constraint of skeleton.physicsConstraints) {
+ if (constraint.active) constraint.reset();
}
}
}
}
+}
/** Changes a slot's {@link Slot#getSequenceIndex()} for an attachment's {@link Sequence}. */
export class SequenceTimeline extends Timeline implements SlotTimeline {
diff --git a/spine-ts/spine-core/src/PhysicsConstraint.ts b/spine-ts/spine-core/src/PhysicsConstraint.ts
index 2f6e1d84f..2d10b8ee8 100644
--- a/spine-ts/spine-core/src/PhysicsConstraint.ts
+++ b/spine-ts/spine-core/src/PhysicsConstraint.ts
@@ -76,7 +76,7 @@ export class PhysicsConstraint implements Updatable {
remaining = 0;
lastTime = 0;
- constructor(data: PhysicsConstraintData, skeleton: Skeleton) {
+ constructor (data: PhysicsConstraintData, skeleton: Skeleton) {
this.data = data;
this.skeleton = skeleton;
this.bone = skeleton.bones[data.bone.index];
@@ -128,102 +128,102 @@ export class PhysicsConstraint implements Updatable {
const l = bone.data.length;
switch (physics) {
- case Physics.none:
- return;
- case Physics.reset:
- this.reset();
+ case Physics.none:
+ return;
+ case Physics.reset:
+ this.reset();
// Fall through.
- case Physics.update:
- this.remaining += Math.max(this.skeleton.time - this.lastTime, 0);
- this.lastTime = this.skeleton.time;
+ case Physics.update:
+ this.remaining += Math.max(this.skeleton.time - this.lastTime, 0);
+ this.lastTime = this.skeleton.time;
- const bx = bone.worldX, by = bone.worldY;
- if (this._reset) {
- this._reset = false;
- this.ux = bx;
- this.uy = by;
- } else {
- let remaining = this.remaining, i = this.inertia, step = this.data.step;
- if (x || y) {
- if (x) {
- this.xOffset += (this.ux - bx) * i;
- this.ux = bx;
- }
- if (y) {
- this.yOffset += (this.uy - by) * i;
- this.uy = by;
- }
- if (remaining >= step) {
- const m = this.massInverse * step, e = this.strength, w = this.wind * 100, g = this.gravity * -100;
- const d = Math.pow(this.damping, 60 * step);
- do {
- if (x) {
- this.xVelocity += (w - this.xOffset * e) * m;
- this.xOffset += this.xVelocity * step;
- this.xVelocity *= d;
- }
- if (y) {
- this.yVelocity += (g - this.yOffset * e) * m;
- this.yOffset += this.yVelocity * step;
- this.yVelocity *= d;
- }
- remaining -= step;
- } while (remaining >= step);
- }
- if (x) bone.worldX += this.xOffset * mix * this.data.x;
- if (y) bone.worldY += this.yOffset * mix * this.data.y;
- }
- if (rotateOrShearX || scaleX) {
- let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0;
- if (rotateOrShearX) {
- mr = mix * this.data.rotate;
- let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY, r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr;
- this.rotateOffset += (r - Math.ceil(r * MathUtils.invPI2 - 0.5) * MathUtils.PI2) * i;
- r = this.rotateOffset * mr + ca;
- c = Math.cos(r);
- s = Math.sin(r);
- if (scaleX) {
- r = l * bone.getWorldScaleX();
- if (r > 0) this.scaleOffset += (dx * c + dy * s) * i / r;
+ const bx = bone.worldX, by = bone.worldY;
+ if (this._reset) {
+ this._reset = false;
+ this.ux = bx;
+ this.uy = by;
+ } else {
+ let remaining = this.remaining, i = this.inertia, step = this.data.step;
+ if (x || y) {
+ if (x) {
+ this.xOffset += (this.ux - bx) * i;
+ this.ux = bx;
}
- } else {
- c = Math.cos(ca);
- s = Math.sin(ca);
- const r = l * bone.getWorldScaleX();
- if (r > 0) this.scaleOffset += ((this.cx - bone.worldX) * c + (this.cy - bone.worldY) * s) * i / r;
+ if (y) {
+ this.yOffset += (this.uy - by) * i;
+ this.uy = by;
+ }
+ if (remaining >= step) {
+ const m = this.massInverse * step, e = this.strength, w = this.wind * 100, g = this.gravity * -100;
+ const d = Math.pow(this.damping, 60 * step);
+ do {
+ if (x) {
+ this.xVelocity += (w - this.xOffset * e) * m;
+ this.xOffset += this.xVelocity * step;
+ this.xVelocity *= d;
+ }
+ if (y) {
+ this.yVelocity += (g - this.yOffset * e) * m;
+ this.yOffset += this.yVelocity * step;
+ this.yVelocity *= d;
+ }
+ remaining -= step;
+ } while (remaining >= step);
+ }
+ if (x) bone.worldX += this.xOffset * mix * this.data.x;
+ if (y) bone.worldY += this.yOffset * mix * this.data.y;
}
- remaining = this.remaining;
- if (remaining >= step) {
- const m = this.massInverse * step, e = this.strength, w = this.wind, g = this.gravity;
- const d = Math.pow(this.damping, 60 * step);
- while (true) {
- remaining -= step;
+ if (rotateOrShearX || scaleX) {
+ let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0;
+ if (rotateOrShearX) {
+ mr = mix * this.data.rotate;
+ let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY, r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr;
+ this.rotateOffset += (r - Math.ceil(r * MathUtils.invPI2 - 0.5) * MathUtils.PI2) * i;
+ r = this.rotateOffset * mr + ca;
+ c = Math.cos(r);
+ s = Math.sin(r);
if (scaleX) {
- this.scaleVelocity += (w * c - g * s - this.scaleOffset * e) * m;
- this.scaleOffset += this.scaleVelocity * step;
- this.scaleVelocity *= d;
+ r = l * bone.getWorldScaleX();
+ if (r > 0) this.scaleOffset += (dx * c + dy * s) * i / r;
+ }
+ } else {
+ c = Math.cos(ca);
+ s = Math.sin(ca);
+ const r = l * bone.getWorldScaleX();
+ if (r > 0) this.scaleOffset += ((this.cx - bone.worldX) * c + (this.cy - bone.worldY) * s) * i / r;
+ }
+ remaining = this.remaining;
+ if (remaining >= step) {
+ const m = this.massInverse * step, e = this.strength, w = this.wind, g = this.gravity;
+ const d = Math.pow(this.damping, 60 * step);
+ while (true) {
+ remaining -= step;
+ if (scaleX) {
+ this.scaleVelocity += (w * c - g * s - this.scaleOffset * e) * m;
+ this.scaleOffset += this.scaleVelocity * step;
+ this.scaleVelocity *= d;
+ }
+ if (rotateOrShearX) {
+ this.rotateVelocity += (-0.01 * l * (w * s + g * c) - this.rotateOffset * e) * m;
+ this.rotateOffset += this.rotateVelocity * step;
+ this.rotateVelocity *= d;
+ if (remaining < step) break;
+ const r = this.rotateOffset * mr + ca;
+ c = Math.cos(r);
+ s = Math.sin(r);
+ } else if (remaining < step) //
+ break;
}
- if (rotateOrShearX) {
- this.rotateVelocity += (-0.01 * l * (w * s + g * c) - this.rotateOffset * e) * m;
- this.rotateOffset += this.rotateVelocity * step;
- this.rotateVelocity *= d;
- if (remaining < step) break;
- const r = this.rotateOffset * mr + ca;
- c = Math.cos(r);
- s = Math.sin(r);
- } else if (remaining < step) //
- break;
}
}
+ this.remaining = remaining;
}
- this.remaining = remaining;
- }
- this.cx = bone.worldX;
- this.cy = bone.worldY;
- break;
- case Physics.pose:
- if (x) bone.worldX += this.xOffset * mix * this.data.x;
- if (y) bone.worldY += this.yOffset * mix * this.data.y;
+ this.cx = bone.worldX;
+ this.cy = bone.worldY;
+ break;
+ case Physics.pose:
+ if (x) bone.worldX += this.xOffset * mix * this.data.x;
+ if (y) bone.worldY += this.yOffset * mix * this.data.y;
}
if (rotateOrShearX) {
diff --git a/spine-ts/spine-core/src/PhysicsConstraintData.ts b/spine-ts/spine-core/src/PhysicsConstraintData.ts
index c023388a4..ee590718e 100644
--- a/spine-ts/spine-core/src/PhysicsConstraintData.ts
+++ b/spine-ts/spine-core/src/PhysicsConstraintData.ts
@@ -34,7 +34,7 @@ import { ConstraintData } from "./ConstraintData.js";
/** Stores the setup pose for a {@link PhysicsConstraint}.
*
* See Physics constraints in the Spine User Guide. */
-export class PhysicsConstraintData extends ConstraintData {
+export class PhysicsConstraintData extends ConstraintData {
private _bone: BoneData | null = null;
/** The bone constrained by this physics constraint. */
public set bone (boneData: BoneData) { this._bone = boneData; }
diff --git a/spine-ts/spine-core/src/Utils.ts b/spine-ts/spine-core/src/Utils.ts
index e45315143..b8db72837 100644
--- a/spine-ts/spine-core/src/Utils.ts
+++ b/spine-ts/spine-core/src/Utils.ts
@@ -199,7 +199,7 @@ export class MathUtils {
return Math.sin(degrees * MathUtils.degRad);
}
- static atan2Deg(y: number, x: number) {
+ static atan2Deg (y: number, x: number) {
return Math.atan2(y, x) * MathUtils.degRad;
}