From a94b17292dc4605127cfa4c6a0f79ec4f6b9d805 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Thu, 26 Feb 2026 11:50:49 +0100 Subject: [PATCH] Removed animation speed in favor or AnimationState.timeScale. Add expression to get its value. --- spine-ts/spine-construct3/src/aces.json | 12 +++++++++--- .../spine-construct3/src/c3runtime/actions.ts | 4 ++-- .../src/c3runtime/expressions.ts | 4 ++++ .../spine-construct3/src/c3runtime/instance.ts | 11 +++++------ spine-ts/spine-construct3/src/lang/en-US.json | 18 +++++++++++------- spine-ts/spine-construct3/src/lang/zh-CN.json | 18 +++++++++++------- 6 files changed, 42 insertions(+), 25 deletions(-) diff --git a/spine-ts/spine-construct3/src/aces.json b/spine-ts/spine-construct3/src/aces.json index b3529f2ef..67820e10a 100644 --- a/spine-ts/spine-construct3/src/aces.json +++ b/spine-ts/spine-construct3/src/aces.json @@ -266,12 +266,12 @@ ] }, { - "id": "set-animation-speed", - "scriptName": "SetAnimationSpeed", + "id": "set-time-scale", + "scriptName": "SetTimeScale", "highlight": false, "params": [ { - "id": "speed", + "id": "time-scale", "type": "number" } ] @@ -719,6 +719,12 @@ "type": "string" } ] + }, + { + "id": "time-scale", + "expressionName": "TimeScale", + "highlight": false, + "returnType": "number" } ] } diff --git a/spine-ts/spine-construct3/src/c3runtime/actions.ts b/spine-ts/spine-construct3/src/c3runtime/actions.ts index 0b68cc18d..288055b3b 100644 --- a/spine-ts/spine-construct3/src/c3runtime/actions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/actions.ts @@ -85,8 +85,8 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts = this.setCustomSkin(skinName); }, - SetAnimationSpeed (this: SDKInstanceClass, speed: number) { - this.setAnimationSpeed(speed); + SetTimeScale (this: SDKInstanceClass, timeScale: number) { + this.setAnimationSpeed(timeScale); }, SetAnimationTime (this: SDKInstanceClass, track: number, time: number, units: 0 | 1) { diff --git a/spine-ts/spine-construct3/src/c3runtime/expressions.ts b/spine-ts/spine-construct3/src/c3runtime/expressions.ts index 97aafabb4..b6f820861 100644 --- a/spine-ts/spine-construct3/src/c3runtime/expressions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/expressions.ts @@ -79,5 +79,9 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Exps = if (field === "animation") return this.triggeredEventData?.animation ?? 0; if (field === "track") return this.triggeredEventData?.track ?? -1; return ""; + }, + + TimeScale (this: SpineC3Instance) { + return this.state?.timeScale ?? 1; } }; diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index f40311c85..a43a4a20f 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -57,7 +57,6 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { collisionSpriteInstance?: IWorldInstance; collisionSpriteClassName = ""; isPlaying = true; - animationSpeed = 1.0; physicsMode = spine.Physics.update; customSkins: Record = {}; @@ -176,13 +175,12 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { } private update (delta: number) { - const { state, skeleton, animationSpeed, physicsMode, matrix } = this; + const { state, skeleton, physicsMode, matrix } = this; if (!skeleton || !state) return; - const adjustedDelta = delta * animationSpeed; - state.update(adjustedDelta); - skeleton.update(adjustedDelta); + state.update(delta); + skeleton.update(delta); state.apply(skeleton); this.updateHandles(skeleton, matrix); @@ -580,7 +578,8 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { } public setAnimationSpeed (speed: number) { - this.animationSpeed = speed; + if (!this.state) return; + this.state.timeScale = speed; } public setAnimationTime (units: 0 | 1, time: number, track: number) { diff --git a/spine-ts/spine-construct3/src/lang/en-US.json b/spine-ts/spine-construct3/src/lang/en-US.json index f4b8b947b..e200065c0 100644 --- a/spine-ts/spine-construct3/src/lang/en-US.json +++ b/spine-ts/spine-construct3/src/lang/en-US.json @@ -345,14 +345,14 @@ } } }, - "set-animation-speed": { - "list-name": "Set animation speed", - "display-text": "Set animation speed to {0}", - "description": "Set the playback speed of animations (1.0 = normal, 2.0 = double speed, 0.5 = half speed)", + "set-time-scale": { + "list-name": "Set time scale", + "display-text": "Set time scale to {0}", + "description": "Set the time scale of animations (1.0 = normal, 2.0 = double speed, 0.5 = half speed)", "params": { - "speed": { - "name": "Speed", - "desc": "Animation speed multiplier (1.0 is normal speed)" + "time-scale": { + "name": "Time scale", + "desc": "Time scale multiplier (1.0 is normal speed)" } } }, @@ -807,6 +807,10 @@ "desc": "The event data field to retrieve" } } + }, + "time-scale": { + "description": "Get the current animation time scale (speed multiplier).", + "translated-name": "TimeScale" } }, "custom_ui": { diff --git a/spine-ts/spine-construct3/src/lang/zh-CN.json b/spine-ts/spine-construct3/src/lang/zh-CN.json index f1791741e..3e5e86e1e 100644 --- a/spine-ts/spine-construct3/src/lang/zh-CN.json +++ b/spine-ts/spine-construct3/src/lang/zh-CN.json @@ -345,14 +345,14 @@ } } }, - "set-animation-speed": { - "list-name": "设置动画速度", - "display-text": "将动画速度设置为{0}", - "description": "设置动画播放速度(1.0 = 正常,2.0 = 两倍速,0.5 = 半速)", + "set-time-scale": { + "list-name": "设置时间缩放", + "display-text": "将时间缩放设置为{0}", + "description": "设置动画时间缩放(1.0 = 正常,2.0 = 两倍速,0.5 = 半速)", "params": { - "speed": { - "name": "速度", - "desc": "动画速度倍数(1.0为正常速度)" + "time-scale": { + "name": "时间缩放", + "desc": "时间缩放倍数(1.0为正常速度)" } } }, @@ -807,6 +807,10 @@ "desc": "要检索的事件数据字段" } } + }, + "time-scale": { + "description": "获取当前动画时间缩放(速度倍数)。", + "translated-name": "TimeScale" } }, "custom_ui": {