next2d-development-mcp 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/references/develop-specs.md +63 -0
- package/dist/references/player-display-objects.md +603 -0
- package/dist/references/player-events.md +308 -0
- package/dist/references/player-filters.md +338 -0
- package/dist/references/player-media-text.md +529 -0
- package/dist/references/player-overview.md +210 -0
- package/dist/references/player-tween.md +278 -0
- package/package.json +2 -2
- package/dist/references/player-specs.md +0 -3539
|
@@ -1286,6 +1286,69 @@ export class TopBtnMolecule extends ButtonAtom {
|
|
|
1286
1286
|
}
|
|
1287
1287
|
```
|
|
1288
1288
|
|
|
1289
|
+
### 親 Sprite コンテナの 0,0 中心設計(アニメーション推奨パターン)
|
|
1290
|
+
|
|
1291
|
+
アニメーション用の親 Sprite コンテナは、**0,0 を視覚的コンテンツの中心点に設計する**のが推奨。
|
|
1292
|
+
`rotation` / `scaleX` / `scaleY` はすべて 0,0 を軸に動くため、0,0 が左上だと回転・拡縮が視覚的にズレる。
|
|
1293
|
+
|
|
1294
|
+
```
|
|
1295
|
+
0,0(中心点)
|
|
1296
|
+
|
|
|
1297
|
+
------+------
|
|
1298
|
+
| |
|
|
1299
|
+
| content |
|
|
1300
|
+
| |
|
|
1301
|
+
-------------
|
|
1302
|
+
(-w/2, -h/2) (w/2, -h/2)
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
#### NG: 0,0 が左上になるパターン(頻出バグ)
|
|
1306
|
+
|
|
1307
|
+
```typescript
|
|
1308
|
+
// NG: container の 0,0 が左上 → rotation/scale が左上を基点に動く
|
|
1309
|
+
const container = new Sprite();
|
|
1310
|
+
container.x = stageWidth / 2 - contentWidth / 2; // 左上基準で中央に配置しようとする
|
|
1311
|
+
container.y = stageHeight / 2 - contentHeight / 2;
|
|
1312
|
+
|
|
1313
|
+
const child = new YourContent();
|
|
1314
|
+
container.addChild(child); // child の左上が container の 0,0 に来る
|
|
1315
|
+
// → rotation アニメーションが左上を軸に回転してしまう
|
|
1316
|
+
```
|
|
1317
|
+
|
|
1318
|
+
#### OK: 0,0 が中心点になるパターン(推奨)
|
|
1319
|
+
|
|
1320
|
+
```typescript
|
|
1321
|
+
// OK: container の 0,0 = 視覚的中心点 → rotation/scale が中心を基点に動く
|
|
1322
|
+
const container = new Sprite();
|
|
1323
|
+
container.x = stageWidth / 2; // 中心座標を設定
|
|
1324
|
+
container.y = stageHeight / 2;
|
|
1325
|
+
|
|
1326
|
+
const child = new YourContent();
|
|
1327
|
+
// child のサイズ確定後にオフセットを計算
|
|
1328
|
+
child.x = -child.width / 2;
|
|
1329
|
+
child.y = -child.height / 2;
|
|
1330
|
+
container.addChild(child);
|
|
1331
|
+
// → rotation / scaleX / scaleY アニメーションが中心を基点に自然に動く
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
複数の子オブジェクトを持つ場合も同様に、全ての child を中心基準でオフセット配置する:
|
|
1335
|
+
|
|
1336
|
+
```typescript
|
|
1337
|
+
const container = new Sprite();
|
|
1338
|
+
container.x = stageWidth / 2;
|
|
1339
|
+
container.y = stageHeight / 2;
|
|
1340
|
+
|
|
1341
|
+
for (const item of items) {
|
|
1342
|
+
const child = new ItemAtom(item);
|
|
1343
|
+
// 各 child も中心基準でオフセット
|
|
1344
|
+
child.x = -child.width / 2;
|
|
1345
|
+
child.y = -child.height / 2 + indexOffset; // 縦並びなどのレイアウト調整
|
|
1346
|
+
container.addChild(child);
|
|
1347
|
+
}
|
|
1348
|
+
```
|
|
1349
|
+
|
|
1350
|
+
---
|
|
1351
|
+
|
|
1289
1352
|
### DisplayObject の中心点基準配置(scale・rotation アニメーション必須)
|
|
1290
1353
|
|
|
1291
1354
|
`scaleX` / `scaleY` / `rotation` を変更すると `width` / `height` の値が変わる。
|
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
# Next2D Player - 表示オブジェクト(DisplayObject / Sprite / MovieClip / Shape)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# DisplayObject
|
|
6
|
+
|
|
7
|
+
DisplayObjectは、Next2D Playerにおける全ての表示オブジェクトの基底クラスです。
|
|
8
|
+
|
|
9
|
+
## クラス階層
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
DisplayObject (基底クラス)
|
|
13
|
+
├── InteractiveObject
|
|
14
|
+
│ ├── DisplayObjectContainer
|
|
15
|
+
│ │ └── Sprite
|
|
16
|
+
│ │ └── MovieClip ← addChild() 可能、タイムラインアニメーション
|
|
17
|
+
│ └── TextField ← addChild() 不可、テキスト表示/入力
|
|
18
|
+
├── Shape ← addChild() 不可、軽量ベクター描画専用
|
|
19
|
+
└── Video ← addChild() 不可、動画再生専用
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## プロパティ
|
|
23
|
+
|
|
24
|
+
### 読み取り専用プロパティ
|
|
25
|
+
|
|
26
|
+
| プロパティ | 型 | 説明 |
|
|
27
|
+
|-----------|------|------|
|
|
28
|
+
| `instanceId` | number | DisplayObjectのユニークなインスタンスID |
|
|
29
|
+
| `isSprite` | boolean | Spriteの機能を所持しているかを返却 |
|
|
30
|
+
| `isInteractive` | boolean | InteractiveObjectの機能を所持しているかを返却 |
|
|
31
|
+
| `isContainerEnabled` | boolean | コンテナの機能を所持しているかを返却 |
|
|
32
|
+
| `isTimelineEnabled` | boolean | MovieClipの機能を所持しているかを返却 |
|
|
33
|
+
| `isShape` | boolean | Shapeの機能を所持しているかを返却 |
|
|
34
|
+
| `isVideo` | boolean | Videoの機能を所持しているかを返却 |
|
|
35
|
+
| `isText` | boolean | Textの機能を所持しているかを返却 |
|
|
36
|
+
| `concatenatedMatrix` | Matrix | ルートレベルまでの結合された変換行列 |
|
|
37
|
+
| `namespace` | string | クラスの空間名(例: `"next2d.display.Sprite"`)を返却。クラス判定に使用する |
|
|
38
|
+
|
|
39
|
+
### 読み書きプロパティ
|
|
40
|
+
|
|
41
|
+
| プロパティ | 型 | 説明 |
|
|
42
|
+
|-----------|------|------|
|
|
43
|
+
| `name` | string | 名前。getChildByName()で使用される(デフォルト: "") |
|
|
44
|
+
| `alpha` | number | アルファ透明度値(0.0~1.0、デフォルト: 1.0) |
|
|
45
|
+
| `blendMode` | string | 使用するブレンドモード(デフォルト: BlendMode.NORMAL) |
|
|
46
|
+
| `filters` | Array \| null | 表示オブジェクトに関連付けられている各フィルターオブジェクトの配列 |
|
|
47
|
+
| `height` | number | 表示オブジェクトの高さ(ピクセル単位) |
|
|
48
|
+
| `width` | number | 表示オブジェクトの幅(ピクセル単位) |
|
|
49
|
+
| `colorTransform` | ColorTransform | 表示オブジェクトのColorTransform |
|
|
50
|
+
| `matrix` | Matrix | 表示オブジェクトのMatrix |
|
|
51
|
+
| `rotation` | number | DisplayObjectインスタンスの回転角度(度単位) |
|
|
52
|
+
| `scaleX` | number | 基準点から適用されるオブジェクトの水平スケール値 |
|
|
53
|
+
| `scaleY` | number | 基準点から適用されるオブジェクトの垂直スケール値 |
|
|
54
|
+
| `visible` | boolean | 表示オブジェクトが可視かどうか(デフォルト: true) |
|
|
55
|
+
| `x` | number | 親DisplayObjectContainerのローカル座標を基準にしたX座標 |
|
|
56
|
+
| `y` | number | 親DisplayObjectContainerのローカル座標を基準にしたY座標 |
|
|
57
|
+
| `cacheAsBitmap` | Matrix \| null | ベクター描画やコンテナをビットマップとしてキャッシュするMatrix(nullで解除、Videoには適用不可) |
|
|
58
|
+
|
|
59
|
+
## メソッド
|
|
60
|
+
|
|
61
|
+
| メソッド | 戻り値 | 説明 |
|
|
62
|
+
|---------|--------|------|
|
|
63
|
+
| `getBounds(targetDisplayObject)` | Rectangle | 指定したDisplayObjectの座標系を基準にして、表示オブジェクトの領域を定義する矩形を返す |
|
|
64
|
+
| `globalToLocal(point)` | Point | pointオブジェクトをステージ(グローバル)座標から表示オブジェクトの(ローカル)座標に変換 |
|
|
65
|
+
| `localToGlobal(point)` | Point | pointオブジェクトを表示オブジェクトの(ローカル)座標からステージ(グローバル)座標に変換 |
|
|
66
|
+
| `hitTestObject(targetDisplayObject)` | boolean | DisplayObjectの描画範囲を評価して、重複または交差するかどうかを調べる |
|
|
67
|
+
| `hitTestPoint(x, y, shapeFlag)` | boolean | 表示オブジェクトを評価して、x および y パラメーターで指定されたポイントと重複または交差するかどうかを調べる |
|
|
68
|
+
| `getLocalVariable(key)` | any | クラスのローカル変数空間から値を取得 |
|
|
69
|
+
| `setLocalVariable(key, value)` | void | クラスのローカル変数空間へ値を保存 |
|
|
70
|
+
| `hasLocalVariable(key)` | boolean | クラスのローカル変数空間に値があるかどうかを判断 |
|
|
71
|
+
| `deleteLocalVariable(key)` | void | クラスのローカル変数空間の値を削除 |
|
|
72
|
+
| `getGlobalVariable(key)` | any | グローバル変数空間から値を取得 |
|
|
73
|
+
| `setGlobalVariable(key, value)` | void | グローバル変数空間へ値を保存 |
|
|
74
|
+
| `hasGlobalVariable(key)` | boolean | グローバル変数空間に値があるかどうかを判断 |
|
|
75
|
+
| `deleteGlobalVariable(key)` | void | グローバル変数空間の値を削除 |
|
|
76
|
+
| `clearGlobalVariable()` | void | グローバル変数空間の値を全てクリア |
|
|
77
|
+
| `remove()` | void | 親子関係を解除 |
|
|
78
|
+
|
|
79
|
+
## ブレンドモード
|
|
80
|
+
|
|
81
|
+
| 定数 | 説明 |
|
|
82
|
+
|------|------|
|
|
83
|
+
| `BlendMode.NORMAL` | 通常表示 |
|
|
84
|
+
| `BlendMode.ADD` | 加算 |
|
|
85
|
+
| `BlendMode.MULTIPLY` | 乗算 |
|
|
86
|
+
| `BlendMode.SCREEN` | スクリーン |
|
|
87
|
+
| `BlendMode.DARKEN` | 暗くする |
|
|
88
|
+
| `BlendMode.LIGHTEN` | 明るくする |
|
|
89
|
+
| `BlendMode.DIFFERENCE` | 差分 |
|
|
90
|
+
| `BlendMode.OVERLAY` | オーバーレイ |
|
|
91
|
+
| `BlendMode.HARDLIGHT` | ハードライト |
|
|
92
|
+
| `BlendMode.INVERT` | 反転 |
|
|
93
|
+
| `BlendMode.ALPHA` | アルファ |
|
|
94
|
+
| `BlendMode.ERASE` | 消去 |
|
|
95
|
+
|
|
96
|
+
## cacheAsBitmapの使い方
|
|
97
|
+
|
|
98
|
+
`cacheAsBitmap`はベクター描画やコンテナをビットマップとしてキャッシュし、2回目以降の描画でキャッシュを再利用することでパフォーマンスを向上させるプロパティです。
|
|
99
|
+
|
|
100
|
+
**適用対象クラス:** `Shape` / `TextField` / `Sprite` / `MovieClip`(`Video`には適用不可)
|
|
101
|
+
|
|
102
|
+
**Matrixの制限:** スケール値(a, d)のみ設定できます。回転(b, c)や移動(tx, ty)は無視されます。
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// ✅ 正しい使い方(スケールのみ設定)
|
|
106
|
+
shape.cacheAsBitmap = new Matrix(1, 0, 0, 1, 0, 0); // 等倍
|
|
107
|
+
shape.cacheAsBitmap = new Matrix(2, 0, 0, 2, 0, 0); // 2倍品質
|
|
108
|
+
|
|
109
|
+
// キャッシュを解除
|
|
110
|
+
shape.cacheAsBitmap = null;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**キャッシュの動作:**
|
|
114
|
+
- 先祖や自身のスケールが変更されるとキャッシュが無効化され、次フレームで再生成
|
|
115
|
+
- 位置(x, y)の変更ではキャッシュは維持され、描画位置のみ更新
|
|
116
|
+
- `filter`と`cacheAsBitmap`を同時に設定した場合、`cacheAsBitmap`が優先
|
|
117
|
+
|
|
118
|
+
## クラス判定(namespace)
|
|
119
|
+
|
|
120
|
+
クラスの種類を判定する際に `constructor.name` を使用してはいけません。プロダクションビルドでは minify によってクラス名が変わるためです。
|
|
121
|
+
|
|
122
|
+
代わりに `namespace` プロパティを使用します。
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const { Stage, Sprite } = next2d.display;
|
|
126
|
+
|
|
127
|
+
// ❌ NG: minify でクラス名が変わるため、ビルド後に判定が壊れる
|
|
128
|
+
if (displayObject.constructor.name === "Stage") { /* ... */ }
|
|
129
|
+
|
|
130
|
+
// ✅ OK: インスタンスの namespace で判定
|
|
131
|
+
if (displayObject.namespace === "next2d.display.Stage") { /* ... */ }
|
|
132
|
+
|
|
133
|
+
// ✅ OK: static の namespace と比較するとタイポも防げる
|
|
134
|
+
if (displayObject.namespace === Stage.namespace) { /* ... */ }
|
|
135
|
+
|
|
136
|
+
// ✅ OK: isStage フラグも使用可能(Stage のみが持つ readonly プロパティ)
|
|
137
|
+
if (displayObject.isStage) { /* ... */ }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**namespace を持つ主なクラス:**
|
|
141
|
+
|
|
142
|
+
| クラス | namespace の値 |
|
|
143
|
+
|--------|----------------|
|
|
144
|
+
| `Stage` | `"next2d.display.Stage"` |
|
|
145
|
+
| `Sprite` | `"next2d.display.Sprite"` |
|
|
146
|
+
| `MovieClip` | `"next2d.display.MovieClip"` |
|
|
147
|
+
| `Shape` | `"next2d.display.Shape"` |
|
|
148
|
+
| `Loader` | `"next2d.display.Loader"` |
|
|
149
|
+
| `TextField` | `"next2d.display.TextField"` |
|
|
150
|
+
| `Video` | `"next2d.media.Video"` |
|
|
151
|
+
|
|
152
|
+
**補足:** 継承を含めた機能判定には `isStage` / `isSprite` / `isShape` / `isText` / `isVideo` / `isContainerEnabled` / `isTimelineEnabled` の各フラグを使用します。`namespace` は完全一致のクラス判定に使用します。
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
# Sprite
|
|
157
|
+
|
|
158
|
+
SpriteはDisplayObjectContainerです。MovieClipの基底クラスであり、タイムラインを持たない動的なオブジェクト管理に使用します。
|
|
159
|
+
|
|
160
|
+
## 継承関係
|
|
161
|
+
|
|
162
|
+
```mermaid
|
|
163
|
+
classDiagram
|
|
164
|
+
DisplayObject <|-- InteractiveObject
|
|
165
|
+
InteractiveObject <|-- DisplayObjectContainer
|
|
166
|
+
DisplayObjectContainer <|-- Sprite
|
|
167
|
+
Sprite <|-- MovieClip
|
|
168
|
+
|
|
169
|
+
class Sprite {
|
|
170
|
+
+buttonMode: Boolean
|
|
171
|
+
+useHandCursor: Boolean
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## プロパティ
|
|
176
|
+
|
|
177
|
+
### Sprite固有のプロパティ
|
|
178
|
+
|
|
179
|
+
| プロパティ | 型 | デフォルト | 説明 |
|
|
180
|
+
|-----------|------|------------|------|
|
|
181
|
+
| `isSprite` | boolean | true | Spriteの機能を所持しているかを返却 |
|
|
182
|
+
| `buttonMode` | boolean | false | このスプライトのボタンモードを指定します |
|
|
183
|
+
| `useHandCursor` | boolean | true | buttonModeがtrueの場合にハンドカーソルを表示するかどうか |
|
|
184
|
+
| `hitArea` | Sprite \| null | null | スプライトのヒット領域となる別のスプライトを指定します |
|
|
185
|
+
|
|
186
|
+
## メソッド
|
|
187
|
+
|
|
188
|
+
| メソッド | 戻り値 | 説明 |
|
|
189
|
+
|---------|--------|------|
|
|
190
|
+
| `startDrag(lockCenter?, bounds?)` | void | 指定されたスプライトをユーザーがドラッグできるようにします |
|
|
191
|
+
| `stopDrag()` | void | startDrag()メソッドを終了します |
|
|
192
|
+
| `addChild(child)` | DisplayObject | 子DisplayObjectインスタンスを追加します |
|
|
193
|
+
| `addChildAt(child, index)` | DisplayObject | 指定のインデックス位置に子DisplayObjectインスタンスを追加します |
|
|
194
|
+
| `removeChild(child)` | void | 指定のchild DisplayObjectインスタンスを削除します |
|
|
195
|
+
| `removeChildAt(index)` | void | 指定のインデックス位置から子DisplayObjectを削除します |
|
|
196
|
+
| `removeChildren(...indexes)` | void | 配列で指定されたインデックスの子をコンテナから削除します |
|
|
197
|
+
| `getChildAt(index)` | DisplayObject \| null | 指定のインデックス位置にある子表示オブジェクトインスタンスを返します |
|
|
198
|
+
| `getChildByName(name)` | DisplayObject \| null | 指定された名前に一致する子表示オブジェクトを返します |
|
|
199
|
+
| `getChildIndex(child)` | number | 子DisplayObjectインスタンスのインデックス位置を返します |
|
|
200
|
+
| `setChildIndex(child, index)` | void | 表示オブジェクトコンテナの既存の子の位置を変更します |
|
|
201
|
+
| `contains(child)` | boolean | 指定されたDisplayObjectがインスタンスの子孫であるかどうか |
|
|
202
|
+
| `swapChildren(child1, child2)` | void | 指定された2つの子オブジェクトのz順序を入れ替えます |
|
|
203
|
+
| `swapChildrenAt(index1, index2)` | void | 指定されたインデックス位置の2つの子オブジェクトのz順序を入れ替えます |
|
|
204
|
+
|
|
205
|
+
## 使用例
|
|
206
|
+
|
|
207
|
+
### ボタンとして使用
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const { Sprite, Shape } = next2d.display;
|
|
211
|
+
const { PointerEvent } = next2d.events;
|
|
212
|
+
|
|
213
|
+
const button = new Sprite();
|
|
214
|
+
button.buttonMode = true;
|
|
215
|
+
button.useHandCursor = true;
|
|
216
|
+
|
|
217
|
+
const bg = new Shape();
|
|
218
|
+
bg.graphics.beginFill(0x3498db);
|
|
219
|
+
bg.graphics.drawRoundRect(0, 0, 120, 40, 8, 8);
|
|
220
|
+
bg.graphics.endFill();
|
|
221
|
+
button.addChild(bg);
|
|
222
|
+
|
|
223
|
+
button.addEventListener(PointerEvent.POINTER_DOWN, () => {
|
|
224
|
+
console.log("ボタンがクリックされました");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
stage.addChild(button);
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### マスクとして使用
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
const { Sprite, Shape } = next2d.display;
|
|
234
|
+
|
|
235
|
+
const container = new Sprite();
|
|
236
|
+
const content = new Shape();
|
|
237
|
+
content.graphics.beginFill(0xFF0000);
|
|
238
|
+
content.graphics.drawRect(0, 0, 200, 200);
|
|
239
|
+
content.graphics.endFill();
|
|
240
|
+
container.addChild(content);
|
|
241
|
+
|
|
242
|
+
const maskShape = new Shape();
|
|
243
|
+
maskShape.graphics.beginFill(0xFFFFFF);
|
|
244
|
+
maskShape.graphics.drawCircle(100, 100, 50);
|
|
245
|
+
maskShape.graphics.endFill();
|
|
246
|
+
|
|
247
|
+
container.mask = maskShape;
|
|
248
|
+
stage.addChild(container);
|
|
249
|
+
stage.addChild(maskShape);
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### ドラッグ&ドロップ
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
const { Sprite, Shape } = next2d.display;
|
|
256
|
+
const { PointerEvent } = next2d.events;
|
|
257
|
+
const { Rectangle } = next2d.geom;
|
|
258
|
+
|
|
259
|
+
const draggable = new Sprite();
|
|
260
|
+
const bg = new Shape();
|
|
261
|
+
bg.graphics.beginFill(0x3498db);
|
|
262
|
+
bg.graphics.drawRect(0, 0, 100, 100);
|
|
263
|
+
bg.graphics.endFill();
|
|
264
|
+
draggable.addChild(bg);
|
|
265
|
+
|
|
266
|
+
draggable.addEventListener(PointerEvent.POINTER_DOWN, () => {
|
|
267
|
+
draggable.startDrag(true, new Rectangle(0, 0, 400, 300));
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
draggable.addEventListener(PointerEvent.POINTER_UP, () => {
|
|
271
|
+
draggable.stopDrag();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
stage.addChild(draggable);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
# MovieClip
|
|
280
|
+
|
|
281
|
+
MovieClipは、タイムラインアニメーションを持つDisplayObjectContainerです。Open Animation Toolで作成したアニメーションはMovieClipとして再生されます。
|
|
282
|
+
|
|
283
|
+
## 継承関係
|
|
284
|
+
|
|
285
|
+
```mermaid
|
|
286
|
+
classDiagram
|
|
287
|
+
DisplayObject <|-- InteractiveObject
|
|
288
|
+
InteractiveObject <|-- DisplayObjectContainer
|
|
289
|
+
DisplayObjectContainer <|-- Sprite
|
|
290
|
+
Sprite <|-- MovieClip
|
|
291
|
+
|
|
292
|
+
class MovieClip {
|
|
293
|
+
+currentFrame: Number
|
|
294
|
+
+totalFrames: Number
|
|
295
|
+
+play()
|
|
296
|
+
+stop()
|
|
297
|
+
+gotoAndPlay()
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## プロパティ
|
|
302
|
+
|
|
303
|
+
| プロパティ | 型 | 説明 |
|
|
304
|
+
|-----------|------|------|
|
|
305
|
+
| `currentFrame` | `number` | MovieClipのタイムライン内の再生ヘッドが置かれているフレームの番号(1から開始、読み取り専用) |
|
|
306
|
+
| `totalFrames` | `number` | MovieClipインスタンス内のフレーム総数(読み取り専用) |
|
|
307
|
+
| `currentFrameLabel` | `FrameLabel \| null` | MovieClipインスタンスのタイムライン内の現在のフレームにあるラベル(読み取り専用) |
|
|
308
|
+
| `currentLabels` | `FrameLabel[] \| null` | 現在のシーンのFrameLabelオブジェクトの配列を返す(読み取り専用) |
|
|
309
|
+
| `isPlaying` | `boolean` | ムービークリップが現在再生されているかどうかを示すブール値(読み取り専用) |
|
|
310
|
+
| `isTimelineEnabled` | `boolean` | MovieClipの機能を所持しているかを返却(読み取り専用) |
|
|
311
|
+
|
|
312
|
+
## メソッド
|
|
313
|
+
|
|
314
|
+
| メソッド | 戻り値 | 説明 |
|
|
315
|
+
|---------|--------|------|
|
|
316
|
+
| `play()` | `void` | ムービークリップのタイムライン内で再生ヘッドを移動する |
|
|
317
|
+
| `stop()` | `void` | ムービークリップ内の再生ヘッドを停止する |
|
|
318
|
+
| `gotoAndPlay(frame: string \| number)` | `void` | 指定されたフレームで再生を開始する |
|
|
319
|
+
| `gotoAndStop(frame: string \| number)` | `void` | 指定されたフレームに再生ヘッドを送り、そこで停止させる |
|
|
320
|
+
| `nextFrame()` | `void` | 次のフレームに再生ヘッドを送り、停止する |
|
|
321
|
+
| `prevFrame()` | `void` | 直前のフレームに再生ヘッドを戻し、停止する |
|
|
322
|
+
| `addFrameLabel(frame_label: FrameLabel)` | `void` | タイムラインに対して動的にLabelを追加する |
|
|
323
|
+
|
|
324
|
+
## 使用例
|
|
325
|
+
|
|
326
|
+
### 基本的なアニメーション制御
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
const { Loader } = next2d.display;
|
|
330
|
+
const { PointerEvent } = next2d.events;
|
|
331
|
+
const { URLRequest } = next2d.net;
|
|
332
|
+
|
|
333
|
+
const loader = new Loader();
|
|
334
|
+
await loader.load(new URLRequest("animation.json"));
|
|
335
|
+
|
|
336
|
+
const mc = loader.content;
|
|
337
|
+
stage.addChild(mc);
|
|
338
|
+
|
|
339
|
+
mc.stop();
|
|
340
|
+
|
|
341
|
+
button.addEventListener(PointerEvent.POINTER_DOWN, () => {
|
|
342
|
+
if (mc.isPlaying) {
|
|
343
|
+
mc.stop();
|
|
344
|
+
} else {
|
|
345
|
+
mc.play();
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### フレームラベルを使った制御
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
mc.gotoAndStop("idle");
|
|
354
|
+
|
|
355
|
+
function changeState(state) {
|
|
356
|
+
switch (state) {
|
|
357
|
+
case "idle": mc.gotoAndPlay("idle"); break;
|
|
358
|
+
case "walk": mc.gotoAndPlay("walk_start"); break;
|
|
359
|
+
case "attack": mc.gotoAndPlay("attack"); break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### ネストしたMovieClipの制御
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
const childMc = mc.getChildByName("character");
|
|
368
|
+
childMc.gotoAndPlay("run");
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### フレームラベルの動的追加
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
const { FrameLabel } = next2d.display;
|
|
375
|
+
|
|
376
|
+
const label = new FrameLabel("myLabel", 10);
|
|
377
|
+
mc.addFrameLabel(label);
|
|
378
|
+
mc.gotoAndPlay("myLabel");
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
# Shape
|
|
384
|
+
|
|
385
|
+
Shapeは、ベクターグラフィックスの描画専用クラスです。Spriteと異なり子オブジェクトを持てませんが、軽量でパフォーマンスに優れています。
|
|
386
|
+
|
|
387
|
+
## 継承関係
|
|
388
|
+
|
|
389
|
+
```mermaid
|
|
390
|
+
classDiagram
|
|
391
|
+
DisplayObject <|-- Shape
|
|
392
|
+
|
|
393
|
+
class Shape {
|
|
394
|
+
+graphics: Graphics
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## プロパティ
|
|
399
|
+
|
|
400
|
+
| プロパティ | 型 | 説明 |
|
|
401
|
+
|-----------|------|------|
|
|
402
|
+
| `graphics` | Graphics | この Shape オブジェクトに描画されるベクターの描画コマンドを保持する Graphics オブジェクト(読み取り専用) |
|
|
403
|
+
| `isShape` | boolean | Shapeの機能を所持しているかを返却(読み取り専用) |
|
|
404
|
+
| `cacheKey` | number | ビルドされたキャッシュキー |
|
|
405
|
+
| `cacheParams` | number[] | キャッシュのビルドに利用されるパラメータ(読み取り専用) |
|
|
406
|
+
| `isBitmap` | boolean | ビットマップ描画の判定フラグ |
|
|
407
|
+
| `src` | string | 指定されたパスから画像を読み込み、Graphicsを生成する |
|
|
408
|
+
| `bitmapData` | BitmapData | ビットマップデータを返却(読み取り専用) |
|
|
409
|
+
| `namespace` | string | 指定されたオブジェクトの空間名を返却(読み取り専用) |
|
|
410
|
+
|
|
411
|
+
## メソッド
|
|
412
|
+
|
|
413
|
+
| メソッド | 戻り値 | 説明 |
|
|
414
|
+
|---------|--------|------|
|
|
415
|
+
| `load(url: string)` | Promise\<void\> | 指定されたURLから画像を非同期で読み込み、Graphicsを生成する |
|
|
416
|
+
| `clearBitmapBuffer()` | void | ビットマップデータを解放する |
|
|
417
|
+
| `setBitmapBuffer(width, height, buffer)` | void | RGBAの画像データを設定する |
|
|
418
|
+
|
|
419
|
+
## SpriteとShapeの違い
|
|
420
|
+
|
|
421
|
+
| 特徴 | Shape | Sprite |
|
|
422
|
+
|------|-------|--------|
|
|
423
|
+
| 子オブジェクト | 持てない | 持てる |
|
|
424
|
+
| インタラクション | なし | クリック等可能 |
|
|
425
|
+
| パフォーマンス | 軽量 | やや重い |
|
|
426
|
+
| 用途 | 静的な背景、装飾 | ボタン、コンテナ |
|
|
427
|
+
|
|
428
|
+
**型制約の注意:**
|
|
429
|
+
- `Shape` は `DisplayObjectContainer` を継承しない → `addChild()` 不可
|
|
430
|
+
- `Shape` と `Sprite` は直接キャスト不可 → `as unknown as Sprite` の二段階アサーションが必要
|
|
431
|
+
- `hitArea` プロパティの型は `Sprite | null` → `Shape` を渡す場合は型アサーション必須
|
|
432
|
+
|
|
433
|
+
## 使用例
|
|
434
|
+
|
|
435
|
+
### 基本的な描画
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
const { Shape } = next2d.display;
|
|
439
|
+
|
|
440
|
+
const shape = new Shape();
|
|
441
|
+
|
|
442
|
+
shape.graphics.beginFill(0x3498db);
|
|
443
|
+
shape.graphics.drawRect(0, 0, 150, 100);
|
|
444
|
+
shape.graphics.endFill();
|
|
445
|
+
|
|
446
|
+
stage.addChild(shape);
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### 複合図形の描画
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
const { Shape } = next2d.display;
|
|
453
|
+
|
|
454
|
+
const shape = new Shape();
|
|
455
|
+
const g = shape.graphics;
|
|
456
|
+
|
|
457
|
+
g.beginFill(0xecf0f1);
|
|
458
|
+
g.drawRoundRect(0, 0, 200, 150, 10, 10);
|
|
459
|
+
g.endFill();
|
|
460
|
+
|
|
461
|
+
g.lineStyle(2, 0x2c3e50);
|
|
462
|
+
g.drawRoundRect(0, 0, 200, 150, 10, 10);
|
|
463
|
+
|
|
464
|
+
g.beginFill(0xe74c3c);
|
|
465
|
+
g.drawCircle(100, 75, 30);
|
|
466
|
+
g.endFill();
|
|
467
|
+
|
|
468
|
+
stage.addChild(shape);
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### グラデーション背景
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
const { Shape } = next2d.display;
|
|
475
|
+
const { Matrix } = next2d.geom;
|
|
476
|
+
|
|
477
|
+
const shape = new Shape();
|
|
478
|
+
const g = shape.graphics;
|
|
479
|
+
|
|
480
|
+
const matrix = new Matrix();
|
|
481
|
+
matrix.createGradientBox(
|
|
482
|
+
stage.stageWidth,
|
|
483
|
+
stage.stageHeight,
|
|
484
|
+
Math.PI / 2,
|
|
485
|
+
0, 0
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
g.beginGradientFill(
|
|
489
|
+
"radial",
|
|
490
|
+
[0x667eea, 0x764ba2],
|
|
491
|
+
[1, 1],
|
|
492
|
+
[0, 255],
|
|
493
|
+
matrix
|
|
494
|
+
);
|
|
495
|
+
g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
|
|
496
|
+
g.endFill();
|
|
497
|
+
|
|
498
|
+
stage.addChildAt(shape, 0);
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## パフォーマンスのヒント
|
|
502
|
+
|
|
503
|
+
1. **静的な描画にはShapeを使用**: インタラクションが不要な背景や装飾にはShapeが最適
|
|
504
|
+
2. **描画の最小化**: 頻繁に変更されない場合は一度だけ描画
|
|
505
|
+
3. **clear()の使用**: 動的な再描画時は必ずclear()を呼ぶ
|
|
506
|
+
4. **複雑な図形はキャッシュ**: cacheAsBitmapプロパティで描画をキャッシュ
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
const { Matrix } = next2d.geom;
|
|
510
|
+
shape.cacheAsBitmap = new Matrix(1, 0, 0, 1, 0, 0);
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### graphicsのパスキャッシュ
|
|
514
|
+
|
|
515
|
+
Shapeの`graphics`は**パス情報をもとにキャッシュキーを生成**します。そのため、`new Shape()`しても同じgraphics情報(パス情報)を持つShapeはキャッシュから描画されます。
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
// 同じパス情報 → キャッシュが再利用される(GPU負荷なし)
|
|
519
|
+
const shape1 = new Shape();
|
|
520
|
+
shape1.graphics.beginFill(0xFF0000).drawCircle(0, 0, 50).endFill();
|
|
521
|
+
|
|
522
|
+
const shape2 = new Shape();
|
|
523
|
+
shape2.graphics.beginFill(0xFF0000).drawCircle(0, 0, 50).endFill(); // キャッシュヒット
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
**キャッシュが有効なプロパティ変更:**
|
|
527
|
+
|
|
528
|
+
色・透明度・x/y座標・回転(`alpha`, `x`, `y`, `rotation`)はキャッシュを再利用したまま変更できるため、描画負荷が非常に小さくなります。
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
// これらはキャッシュを維持したまま変更可能(低負荷)
|
|
532
|
+
shape.alpha = 0.5;
|
|
533
|
+
shape.x = 100;
|
|
534
|
+
shape.y = 200;
|
|
535
|
+
shape.rotation = 45;
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
**scaleがある場合のキャッシュ戦略:**
|
|
539
|
+
|
|
540
|
+
`scaleX` / `scaleY` を使用する場合は、**最終的に表示される最大サイズで`cacheAsBitmap`を設定**し、そのキャッシュをscaleで縮小表示することで描画負荷を抑えられます。
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
const { Shape } = next2d.display;
|
|
544
|
+
const { Matrix } = next2d.geom;
|
|
545
|
+
|
|
546
|
+
const shape = new Shape();
|
|
547
|
+
shape.graphics.beginFill(0x3498db).drawRect(0, 0, 100, 100).endFill();
|
|
548
|
+
|
|
549
|
+
// 最大サイズ(2倍)でキャッシュしてscaleで調整
|
|
550
|
+
shape.cacheAsBitmap = new Matrix(2, 0, 0, 2, 0, 0); // 2倍品質でキャッシュ
|
|
551
|
+
shape.scaleX = 0.5; // キャッシュを縮小して表示(描画負荷なし)
|
|
552
|
+
shape.scaleY = 0.5;
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
# Graphics クラス
|
|
558
|
+
|
|
559
|
+
Graphicsクラスは、ベクターグラフィックスを描画するための描画APIを提供します。Shape.graphicsプロパティを通じてアクセスします。
|
|
560
|
+
|
|
561
|
+
## 塗りつぶしメソッド
|
|
562
|
+
|
|
563
|
+
| メソッド | 説明 |
|
|
564
|
+
|---------|------|
|
|
565
|
+
| `beginFill(color: number, alpha?: number)` | 単色の塗りつぶしを開始。alphaのデフォルトは1 |
|
|
566
|
+
| `beginGradientFill(type, colors, alphas, ratios, matrix?, spreadMethod?, interpolationMethod?, focalPointRatio?)` | グラデーション塗りつぶしを開始 |
|
|
567
|
+
| `beginBitmapFill(bitmapData, matrix?, repeat?, smooth?)` | ビットマップ塗りつぶしを開始 |
|
|
568
|
+
| `endFill()` | 塗りつぶしを終了 |
|
|
569
|
+
|
|
570
|
+
## 線スタイルメソッド
|
|
571
|
+
|
|
572
|
+
| メソッド | 説明 |
|
|
573
|
+
|---------|------|
|
|
574
|
+
| `lineStyle(thickness?, color?, alpha?, pixelHinting?, scaleMode?, caps?, joints?, miterLimit?)` | 線のスタイルを設定 |
|
|
575
|
+
| `lineGradientStyle(type, colors, alphas, ratios, matrix?, ...)` | グラデーション線スタイルを設定 |
|
|
576
|
+
| `lineBitmapStyle(bitmapData, matrix?, repeat?, smooth?)` | ビットマップ線スタイルを設定 |
|
|
577
|
+
| `endLine()` | 線スタイルを終了 |
|
|
578
|
+
|
|
579
|
+
## パスメソッド
|
|
580
|
+
|
|
581
|
+
| メソッド | 説明 |
|
|
582
|
+
|---------|------|
|
|
583
|
+
| `moveTo(x: number, y: number)` | 描画位置を移動 |
|
|
584
|
+
| `lineTo(x: number, y: number)` | 現在位置から指定座標まで直線を描画 |
|
|
585
|
+
| `curveTo(controlX, controlY, anchorX, anchorY)` | 二次ベジェ曲線を描画 |
|
|
586
|
+
| `cubicCurveTo(controlX1, controlY1, controlX2, controlY2, anchorX, anchorY)` | 三次ベジェ曲線を描画 |
|
|
587
|
+
|
|
588
|
+
## 図形メソッド
|
|
589
|
+
|
|
590
|
+
| メソッド | 説明 |
|
|
591
|
+
|---------|------|
|
|
592
|
+
| `drawRect(x, y, width, height)` | 矩形を描画 |
|
|
593
|
+
| `drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight?)` | 角丸矩形を描画 |
|
|
594
|
+
| `drawCircle(x, y, radius)` | 円を描画 |
|
|
595
|
+
| `drawEllipse(x, y, width, height)` | 楕円を描画 |
|
|
596
|
+
|
|
597
|
+
## ユーティリティメソッド
|
|
598
|
+
|
|
599
|
+
| メソッド | 説明 |
|
|
600
|
+
|---------|------|
|
|
601
|
+
| `clear()` | すべての描画コマンドをクリア |
|
|
602
|
+
| `clone()` | Graphicsオブジェクトを複製 |
|
|
603
|
+
| `copyFrom(source: Graphics)` | 別のGraphicsから描画コマンドをコピー |
|