|
| 1 | +# Animation Tool 集成 |
| 2 | + |
| 3 | +Next2D Framework 与使用 Animation Tool 创建的资源无缝集成。 |
| 4 | + |
| 5 | +## 概述 |
| 6 | + |
| 7 | +Animation Tool 是用于为 Next2D Player 创建动画和 UI 组件的工具。输出的 JSON 文件可以在框架中加载并用作 MovieClip。 |
| 8 | + |
| 9 | +## 目录结构 |
| 10 | + |
| 11 | +``` |
| 12 | +src/ |
| 13 | +├── ui/ |
| 14 | +│ ├── content/ # Animation Tool 生成的内容 |
| 15 | +│ │ ├── TopContent.ts |
| 16 | +│ │ └── HomeContent.ts |
| 17 | +│ │ |
| 18 | +│ ├── component/ # 原子设计组件 |
| 19 | +│ │ ├── atom/ # 最小单元组件 |
| 20 | +│ │ │ ├── ButtonAtom.ts |
| 21 | +│ │ │ └── TextAtom.ts |
| 22 | +│ │ ├── molecule/ # 组合的 Atom 组件 |
| 23 | +│ │ │ ├── TopBtnMolecule.ts |
| 24 | +│ │ │ └── HomeBtnMolecule.ts |
| 25 | +│ │ ├── organism/ # 多个 Molecule 组合 |
| 26 | +│ │ ├── template/ # 页面模板 |
| 27 | +│ │ └── page/ # 页面组件 |
| 28 | +│ │ ├── top/ |
| 29 | +│ │ │ └── TopPage.ts |
| 30 | +│ │ └── home/ |
| 31 | +│ │ └── HomePage.ts |
| 32 | +│ │ |
| 33 | +│ └── animation/ # 代码动画定义 |
| 34 | +│ └── top/ |
| 35 | +│ └── TopBtnShowAnimation.ts |
| 36 | +│ |
| 37 | +└── file/ # Animation Tool 输出文件 |
| 38 | + └── sample.n2d |
| 39 | +``` |
| 40 | + |
| 41 | +## MovieClipContent |
| 42 | + |
| 43 | +包装使用 Animation Tool 创建的内容的类。 |
| 44 | + |
| 45 | +### 基本结构 |
| 46 | + |
| 47 | +```typescript |
| 48 | +import { MovieClipContent } from "@next2d/framework"; |
| 49 | + |
| 50 | +/** |
| 51 | + * @see file/sample.n2d |
| 52 | + */ |
| 53 | +export class TopContent extends MovieClipContent |
| 54 | +{ |
| 55 | + /** |
| 56 | + * 返回在 Animation Tool 中设置的符号名称 |
| 57 | + */ |
| 58 | + get namespace(): string |
| 59 | + { |
| 60 | + return "TopContent"; |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### namespace 的作用 |
| 66 | + |
| 67 | +`namespace` 属性应与在 Animation Tool 中创建的符号名称匹配。此名称用于从加载的 JSON 数据生成相应的 MovieClip。 |
| 68 | + |
| 69 | +## 加载内容 |
| 70 | + |
| 71 | +### routing.json 中的配置 |
| 72 | + |
| 73 | +Animation Tool JSON 文件通过 `routing.json` 中的 `requests` 加载。 |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "@sample": { |
| 78 | + "requests": [ |
| 79 | + { |
| 80 | + "type": "content", |
| 81 | + "path": "{{ content.endPoint }}content/sample.json", |
| 82 | + "name": "MainContent", |
| 83 | + "cache": true |
| 84 | + } |
| 85 | + ] |
| 86 | + }, |
| 87 | + "top": { |
| 88 | + "requests": [ |
| 89 | + { |
| 90 | + "type": "cluster", |
| 91 | + "path": "@sample" |
| 92 | + } |
| 93 | + ] |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +#### 请求配置 |
| 99 | + |
| 100 | +| 属性 | 类型 | 说明 | |
| 101 | +|------|------|------| |
| 102 | +| `type` | string | 指定 `"content"` | |
| 103 | +| `path` | string | JSON 文件的路径 | |
| 104 | +| `name` | string | 在响应中注册的键名 | |
| 105 | +| `cache` | boolean | 是否缓存 | |
| 106 | + |
| 107 | +#### 集群功能 |
| 108 | + |
| 109 | +以 `@` 开头的键被定义为集群,可以在多个路由之间共享。使用 `type: "cluster"` 引用它们。 |
| 110 | + |
| 111 | +```json |
| 112 | +{ |
| 113 | + "@common": { |
| 114 | + "requests": [ |
| 115 | + { |
| 116 | + "type": "content", |
| 117 | + "path": "{{ content.endPoint }}common.json", |
| 118 | + "name": "CommonContent", |
| 119 | + "cache": true |
| 120 | + } |
| 121 | + ] |
| 122 | + }, |
| 123 | + "top": { |
| 124 | + "requests": [ |
| 125 | + { "type": "cluster", "path": "@common" } |
| 126 | + ] |
| 127 | + }, |
| 128 | + "home": { |
| 129 | + "requests": [ |
| 130 | + { "type": "cluster", "path": "@common" } |
| 131 | + ] |
| 132 | + } |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +## 相关 |
| 137 | + |
| 138 | +- [View/ViewModel](/cn/reference/framework/view) |
| 139 | +- [路由](/cn/reference/framework/routing) |
| 140 | +- [配置](/cn/reference/framework/config) |
0 commit comments