Removed animation speed in favor or AnimationState.timeScale. Add expression to get its value.

This commit is contained in:
Davide Tantillo 2026-02-26 11:50:49 +01:00
parent 0347e5f6ab
commit a94b17292d
6 changed files with 42 additions and 25 deletions

View File

@ -266,12 +266,12 @@
] ]
}, },
{ {
"id": "set-animation-speed", "id": "set-time-scale",
"scriptName": "SetAnimationSpeed", "scriptName": "SetTimeScale",
"highlight": false, "highlight": false,
"params": [ "params": [
{ {
"id": "speed", "id": "time-scale",
"type": "number" "type": "number"
} }
] ]
@ -719,6 +719,12 @@
"type": "string" "type": "string"
} }
] ]
},
{
"id": "time-scale",
"expressionName": "TimeScale",
"highlight": false,
"returnType": "number"
} }
] ]
} }

View File

@ -85,8 +85,8 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts =
this.setCustomSkin(skinName); this.setCustomSkin(skinName);
}, },
SetAnimationSpeed (this: SDKInstanceClass, speed: number) { SetTimeScale (this: SDKInstanceClass, timeScale: number) {
this.setAnimationSpeed(speed); this.setAnimationSpeed(timeScale);
}, },
SetAnimationTime (this: SDKInstanceClass, track: number, time: number, units: 0 | 1) { SetAnimationTime (this: SDKInstanceClass, track: number, time: number, units: 0 | 1) {

View File

@ -79,5 +79,9 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Exps =
if (field === "animation") return this.triggeredEventData?.animation ?? 0; if (field === "animation") return this.triggeredEventData?.animation ?? 0;
if (field === "track") return this.triggeredEventData?.track ?? -1; if (field === "track") return this.triggeredEventData?.track ?? -1;
return ""; return "";
},
TimeScale (this: SpineC3Instance) {
return this.state?.timeScale ?? 1;
} }
}; };

View File

@ -57,7 +57,6 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
collisionSpriteInstance?: IWorldInstance; collisionSpriteInstance?: IWorldInstance;
collisionSpriteClassName = ""; collisionSpriteClassName = "";
isPlaying = true; isPlaying = true;
animationSpeed = 1.0;
physicsMode = spine.Physics.update; physicsMode = spine.Physics.update;
customSkins: Record<string, Skin> = {}; customSkins: Record<string, Skin> = {};
@ -176,13 +175,12 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
} }
private update (delta: number) { private update (delta: number) {
const { state, skeleton, animationSpeed, physicsMode, matrix } = this; const { state, skeleton, physicsMode, matrix } = this;
if (!skeleton || !state) return; if (!skeleton || !state) return;
const adjustedDelta = delta * animationSpeed; state.update(delta);
state.update(adjustedDelta); skeleton.update(delta);
skeleton.update(adjustedDelta);
state.apply(skeleton); state.apply(skeleton);
this.updateHandles(skeleton, matrix); this.updateHandles(skeleton, matrix);
@ -580,7 +578,8 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
} }
public setAnimationSpeed (speed: number) { public setAnimationSpeed (speed: number) {
this.animationSpeed = speed; if (!this.state) return;
this.state.timeScale = speed;
} }
public setAnimationTime (units: 0 | 1, time: number, track: number) { public setAnimationTime (units: 0 | 1, time: number, track: number) {

View File

@ -345,14 +345,14 @@
} }
} }
}, },
"set-animation-speed": { "set-time-scale": {
"list-name": "Set animation speed", "list-name": "Set time scale",
"display-text": "Set animation speed to {0}", "display-text": "Set time scale to {0}",
"description": "Set the playback speed of animations (1.0 = normal, 2.0 = double speed, 0.5 = half speed)", "description": "Set the time scale of animations (1.0 = normal, 2.0 = double speed, 0.5 = half speed)",
"params": { "params": {
"speed": { "time-scale": {
"name": "Speed", "name": "Time scale",
"desc": "Animation speed multiplier (1.0 is normal speed)" "desc": "Time scale multiplier (1.0 is normal speed)"
} }
} }
}, },
@ -807,6 +807,10 @@
"desc": "The event data field to retrieve" "desc": "The event data field to retrieve"
} }
} }
},
"time-scale": {
"description": "Get the current animation time scale (speed multiplier).",
"translated-name": "TimeScale"
} }
}, },
"custom_ui": { "custom_ui": {

View File

@ -345,14 +345,14 @@
} }
} }
}, },
"set-animation-speed": { "set-time-scale": {
"list-name": "设置动画速度", "list-name": "设置时间缩放",
"display-text": "将动画速度设置为{0}", "display-text": "将时间缩放设置为{0}",
"description": "设置动画播放速度1.0 = 正常2.0 = 两倍速0.5 = 半速)", "description": "设置动画时间缩放1.0 = 正常2.0 = 两倍速0.5 = 半速)",
"params": { "params": {
"speed": { "time-scale": {
"name": "速度", "name": "时间缩放",
"desc": "动画速度倍数1.0为正常速度)" "desc": "时间缩放倍数1.0为正常速度)"
} }
} }
}, },
@ -807,6 +807,10 @@
"desc": "要检索的事件数据字段" "desc": "要检索的事件数据字段"
} }
} }
},
"time-scale": {
"description": "获取当前动画时间缩放(速度倍数)。",
"translated-name": "TimeScale"
} }
}, },
"custom_ui": { "custom_ui": {