From ada885ac14e5db7f3109068252b62b31da13e004 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 9 Apr 2026 18:53:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0spine=E7=9A=84stop=E5=92=8Cst?= =?UTF-8?q?opAll=E5=92=8C=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/games/client/Edit/Settings.ini | 20 ++++---- .../Projects/Spine/docs/Spine动画集成手册.md | 51 ++++++++++++++++--- .../client/Projects/Spine/js/SpineMgr.js | 23 +++++++++ 3 files changed, 77 insertions(+), 17 deletions(-) diff --git a/codes/games/client/Edit/Settings.ini b/codes/games/client/Edit/Settings.ini index bc93c87..17b5a26 100644 --- a/codes/games/client/Edit/Settings.ini +++ b/codes/games/client/Edit/Settings.ini @@ -123,16 +123,16 @@ DocumentTypeKeyWordsFile1= DocumentTypeFunctionRegExp1= [MRUFiles] -MRUItem1=G:\Works\YouleGames\codes\games\client\Projects\Project1\js\gamemain.js -MRUItem2=G:\Works\YouleGames\codes\games\client\Projects\Spine\js\gamemain.js -MRUItem3=G:\Works\YouleGames\codes\games\client\Projects\Spine\index.html -MRUItem4=G:\Works\YouleGames\games\games\Projects\clinet\gamehall\js\gamemain.js -MRUItem5=G:\Works\YouleGames\games\games\Projects\clinet\zpy\js\gamemain.js -MRUItem6=G:\Works\YouleGames\games\games\Projects\Project1\js\gamemain.js -MRUItem7=G:\Works\YouleGames\games\games\Projects\clinet\sangelaok\js\gamemain.js -MRUItem8=G:\Works\YouleGames\games\games\Projects\clinet\niuniu\js\gamemain.js -MRUItem9=G:\Works\YouleGames\games\games\Projects\clinet\guanpai-jx\js\gamemain.js -MRUItem10=G:\Works\YouleGames\games\games\Projects\clinet\doudizhu\js\gamemain.js +MRUItem1=G:\Works\YouleGames\codes\games\client\Projects\Spine\js\gamemain.js +MRUItem2=G:\Works\YouleGames\codes\games\client\Projects\Project2\js\gamemain.js +MRUItem3=G:\Works\YouleGames\codes\games\client\Projects\Project1\js\gamemain.js +MRUItem4=G:\Works\YouleGames\codes\games\client\Projects\Spine\index.html +MRUItem5=G:\Works\YouleGames\games\games\Projects\clinet\gamehall\js\gamemain.js +MRUItem6=G:\Works\YouleGames\games\games\Projects\clinet\zpy\js\gamemain.js +MRUItem7=G:\Works\YouleGames\games\games\Projects\Project1\js\gamemain.js +MRUItem8=G:\Works\YouleGames\games\games\Projects\clinet\sangelaok\js\gamemain.js +MRUItem9=G:\Works\YouleGames\games\games\Projects\clinet\niuniu\js\gamemain.js +MRUItem10=G:\Works\YouleGames\games\games\Projects\clinet\guanpai-jx\js\gamemain.js [MRUFindText] MRUItem1= diff --git a/codes/games/client/Projects/Spine/docs/Spine动画集成手册.md b/codes/games/client/Projects/Spine/docs/Spine动画集成手册.md index e7398eb..23c6f2a 100644 --- a/codes/games/client/Projects/Spine/docs/Spine动画集成手册.md +++ b/codes/games/client/Projects/Spine/docs/Spine动画集成手册.md @@ -375,9 +375,43 @@ gameabc_face.spineMgr.playQueue("hero", ["intro", "idle"], false); --- -### 4.14 remove(id) +### 4.14 stop(id) -**销毁指定 Spine 实例,释放内存。** +**停止指定 Spine 实例的动画并隐藏。** 实例保留在内存中,可随时重新播放。 +与 `setVisible(false)` 不同,`stop` 会彻底清空动画轨道、重置骨骼姿态,并清除待执行命令队列。 + +```javascript +// 停止单个 Spine 动画(保留实例,可重播) +gameabc_face.spineMgr.stop("hero"); + +// 之后可以重新播放 +gameabc_face.spineMgr.playOnce("hero", "attack"); +``` + +| 行为 | 说明 | +|------|------| +| 隐藏 | `visible = false` | +| 清空动画轨道 | `state.clearTracks()` | +| 重置骨骼姿态 | `skeleton.setToSetupPose()` | +| 清除待执行命令 | 删除 `_pendingCmds[id]` | +| 清除自动隐藏标记 | `_hideOnComplete = false` | + +--- + +### 4.15 stopAll() + +**停止所有 Spine 实例的动画并隐藏。** 所有实例保留在内存中,可随时重新播放。 + +```javascript +// 停止全部 Spine 动画(如:切换游戏场景时) +gameabc_face.spineMgr.stopAll(); +``` + +--- + +### 4.16 remove(id) + +**彻底销毁指定 Spine 实例,释放内存。** 销毁后无法重新播放,需要重新 `load` 或自动加载。 ```javascript gameabc_face.spineMgr.remove("hero"); @@ -385,15 +419,17 @@ gameabc_face.spineMgr.remove("hero"); --- -### 4.15 removeAll() +### 4.17 removeAll() -**销毁所有 Spine 实例。** +**彻底销毁所有 Spine 实例,释放内存。** ```javascript gameabc_face.spineMgr.removeAll(); ``` -### 4.16 spine_onComplete(spineId, animName, trackIndex) *(事件回调)* +--- + +### 4.18 spine_onComplete(spineId, animName, trackIndex) *(事件回调)* **动画完成回调。每次动画播放一轮结束时触发。** 在 `js/Spine_Event.js` 中定义。 @@ -418,7 +454,7 @@ gameabc_face.spine_onComplete = function(spineId, animName, trackIndex) { --- -### 4.17 spine_onEvent(spineId, eventName, intValue, floatValue, stringValue) *(事件回调)* +### 4.19 spine_onEvent(spineId, eventName, intValue, floatValue, stringValue) *(事件回调)* **自定义事件回调。当动画播放到 Spine 编辑器中定义的 Event 关键帧时触发。** 在 `js/Spine_Event.js` 中定义。 @@ -449,7 +485,7 @@ gameabc_face.spine_onEvent = function(spineId, eventName, intValue, floatValue, ## 5. 事件系统(详细说明) Spine 动画在运行时会触发两类事件,回调定义在 `js/Spine_Event.js` 中。 -API 签名见 [4.16](#416-spine_oncompletespineid-animname-trackindex--事件回调) 和 [4.17](#417-spine_oneventspineid-eventname-intvalue-floatvalue-stringvalue--事件回调)。 +API 签名见 [4.18](#418-spine_oncompletespineid-animname-trackindex--事件回调) 和 [4.19](#419-spine_oneventspineid-eventname-intvalue-floatvalue-stringvalue--事件回调)。 ### 5.1 动画完成事件 spine_onComplete @@ -674,6 +710,7 @@ gameabc_face.gamemydraw = function(gameid, spid, times, timelong) { - Canvas 2D 渲染性能有限,建议同屏 Spine 实例不超过 **5-8 个** - 不可见的实例调用 `setVisible(id, false)`,跳过渲染和更新 +- 场景切换时调用 `stopAll()` 一键关闭所有 Spine 动画 - 不再需要的实例调用 `remove(id)` 释放内存 ### 8.3 减少骨骼复杂度 diff --git a/codes/games/client/Projects/Spine/js/SpineMgr.js b/codes/games/client/Projects/Spine/js/SpineMgr.js index db3fd98..9a989b0 100644 --- a/codes/games/client/Projects/Spine/js/SpineMgr.js +++ b/codes/games/client/Projects/Spine/js/SpineMgr.js @@ -355,12 +355,35 @@ var SpineMgr = { } }, + stop: function(id) { + var e = this._entries[id]; + if (!e) return; + e.visible = false; + e._hideOnComplete = false; + e._hideAfterCompletes = 0; + delete this._pendingCmds[id]; + if (e.state) { + e.state.clearTracks(); + } + if (e.skeleton) { + e.skeleton.setToSetupPose(); + } + }, + + stopAll: function() { + for (var id in this._entries) { + this.stop(id); + } + }, + remove: function(id) { delete this._entries[id]; + delete this._pendingCmds[id]; }, removeAll: function() { this._entries = {}; + this._pendingCmds = {}; } };