增加spine的stop和stopAll和文档

This commit is contained in:
2026-04-09 18:53:22 +08:00
parent a221d681ab
commit ada885ac14
3 changed files with 77 additions and 17 deletions

View File

@@ -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 减少骨骼复杂度