@@ -15,7 +15,7 @@ Separating animation definitions from components improves code reusability and m
1515```
1616animation/
1717└── top/
18- └── TopBtnEntranceAnimation .ts
18+ └── TopBtnShowAnimation .ts
1919```
2020
2121画面ごとにサブディレクトリを作成し、その中にアニメーション定義ファイルを配置します。
@@ -24,7 +24,7 @@ Create subdirectories for each screen and place animation definition files withi
2424
2525## アニメーションの種類 / Animation Types
2626
27- ### 入場アニメーション / Entrance Animation
27+ ### 登場アニメーション / Show Animation
2828
2929画面表示時のアニメーションです。
3030
@@ -44,39 +44,65 @@ Animation in response to user actions.
4444
4545## 実装例 / Implementation Example
4646
47- ### TopBtnEntranceAnimation .ts
47+ ### TopBtnShowAnimation .ts
4848
4949``` typescript
5050import type { TopBtnMolecule } from " @/ui/component/molecule/TopBtnMolecule" ;
51- import { Tween } from " @next2d/framework" ;
51+ import { Tween , Easing , type Job } from " @next2d/ui" ;
52+ import { Event } from " @next2d/events" ;
5253
5354/**
54- * @description Topボタンの入場アニメーション
55- * Entrance animation for Top button
55+ * @description Topボタンの登場アニメーション
56+ * Top Button Entrance Animation
5657 *
57- * @param {TopBtnMolecule} target
58- * @param {() => void} callback
59- * @return {void}
58+ * @class
59+ * @public
6060 */
61- export const playEntrance = (
62- target : TopBtnMolecule ,
63- callback : () => void
64- ): void => {
65- // 初期状態
66- target .alpha = 0 ;
67- target .scaleX = 0.5 ;
68- target .scaleY = 0.5 ;
69-
70- // アニメーション
71- Tween .to (target , {
72- alpha: 1 ,
73- scaleX: 1 ,
74- scaleY: 1 ,
75- duration: 0.5 ,
76- ease: " easeOutBack" ,
77- onComplete: callback
78- });
79- };
61+ export class TopBtnShowAnimation {
62+
63+ private readonly _job: Job ;
64+
65+ /**
66+ * @param {TopBtnMolecule} sprite
67+ * @param {() => void} callback
68+ * @constructor
69+ * @public
70+ */
71+ constructor (
72+ sprite : TopBtnMolecule ,
73+ callback : () => void
74+ ) {
75+
76+ // アニメーションの初期値に設定
77+ sprite .alpha = 0 ;
78+
79+ this ._job = Tween .add (sprite ,
80+ {
81+ " alpha" : 0
82+ },
83+ {
84+ " alpha" : 1
85+ }, 0.5 , 1 , Easing .inQuad
86+ );
87+
88+ // 終了アニメーションが完了したら、完了イベントを発行
89+ this ._job .addEventListener (Event .COMPLETE , (): void =>
90+ {
91+ callback ();
92+ });
93+ }
94+
95+ /**
96+ * @description アニメーション開始
97+ * Start animation
98+ *
99+ * @method
100+ * @public
101+ */
102+ start(): void {
103+ this ._job .start ();
104+ }
105+ }
80106```
81107
82108## 設計原則 / Design Principles
@@ -89,15 +115,15 @@ Separate animation logic from components.
89115
90116``` typescript
91117// ✅ 良い例: アニメーションを別ファイルに分離
92- // animation/top/TopBtnEntranceAnimation .ts
93- export const playEntrance = ( target , callback ) => { ... };
118+ // animation/top/TopBtnShowAnimation .ts
119+ export class TopBtnShowAnimation { ... }
94120
95121// component/molecule/TopBtnMolecule.ts
96- import { playEntrance } from " @/ui/animation/top/TopBtnEntranceAnimation " ;
122+ import { TopBtnShowAnimation } from " @/ui/animation/top/TopBtnShowAnimation " ;
97123
98124export class TopBtnMolecule extends ButtonAtom {
99- playEntrance (callback : () => void ): void {
100- playEntrance (this , callback );
125+ playShow (callback : () => void ): void {
126+ new TopBtnShowAnimation (this , callback ). start ( );
101127 }
102128}
103129```
@@ -109,11 +135,26 @@ export class TopBtnMolecule extends ButtonAtom {
109135Make the same animation usable across multiple components.
110136
111137``` typescript
112- // ✅ 良い例: 汎用的なフェードインアニメーション
113- export const fadeIn = (target : DisplayObject , duration : number = 0.3 ): void => {
114- target .alpha = 0 ;
115- Tween .to (target , { alpha: 1 , duration });
116- };
138+ // ✅ 良い例: 汎用的なフェードインアニメーションクラス
139+ import { Tween , Easing , type Job } from " @next2d/ui" ;
140+ import type { Sprite } from " @next2d/display" ;
141+ import { Event } from " @next2d/events" ;
142+
143+ export class FadeInAnimation {
144+ private readonly _job: Job ;
145+
146+ constructor (target : Sprite , callback ? : () => void ) {
147+ target .alpha = 0 ;
148+ this ._job = Tween .add (target , { " alpha" : 0 }, { " alpha" : 1 }, 0.3 , 1 , Easing .linear );
149+ if (callback ) {
150+ this ._job .addEventListener (Event .COMPLETE , callback );
151+ }
152+ }
153+
154+ start(): void {
155+ this ._job .start ();
156+ }
157+ }
117158```
118159
119160### 3. コールバック対応 / Callback Support
@@ -123,15 +164,24 @@ export const fadeIn = (target: DisplayObject, duration: number = 0.3): void => {
123164Support callbacks for when animation completes.
124165
125166``` typescript
126- export const playEntrance = (
127- target : DisplayObject ,
128- callback ? : () => void
129- ): void => {
130- Tween .to (target , {
131- // ...
132- onComplete: callback
133- });
134- };
167+ import { Tween , Easing , type Job } from " @next2d/ui" ;
168+ import { Event } from " @next2d/events" ;
169+
170+ export class ExampleAnimation {
171+ private readonly _job: Job ;
172+
173+ constructor (target : Sprite , callback ? : () => void ) {
174+ this ._job = Tween .add (target , { " alpha" : 0 }, { " alpha" : 1 }, 0.5 , 1 , Easing .outQuad );
175+
176+ if (callback ) {
177+ this ._job .addEventListener (Event .COMPLETE , callback );
178+ }
179+ }
180+
181+ start(): void {
182+ this ._job .start ();
183+ }
184+ }
135185```
136186
137187## 新しいアニメーションの追加 / Adding New Animations
@@ -146,40 +196,71 @@ export const playEntrance = (
146196### テンプレート / Template
147197
148198``` typescript
149- import type { DisplayObject } from " @next2d/display" ;
150- import { Tween } from " @next2d/framework" ;
199+ import type { Sprite } from " @next2d/display" ;
200+ import { Tween , Easing , type Job } from " @next2d/ui" ;
201+ import { Event } from " @next2d/events" ;
151202
152203/**
153204 * @description [アニメーションの説明]
154205 * [Animation description]
155206 *
156- * @param {DisplayObject} target - アニメーション対象
157- * @param {() => void} callback - 完了時コールバック
158- * @return {void}
207+ * @class
208+ * @public
159209 */
160- export const yourAnimation = (
161- target : DisplayObject ,
162- callback ? : () => void
163- ): void => {
164- // 初期状態設定
165- target .alpha = 0 ;
166-
167- // アニメーション実行
168- Tween .to (target , {
169- alpha: 1 ,
170- duration: 0.5 ,
171- ease: " easeOutQuad" ,
172- onComplete: callback
173- });
174- };
210+ export class YourAnimation {
211+
212+ private readonly _job: Job ;
213+
214+ /**
215+ * @param {Sprite} sprite - アニメーション対象
216+ * @param {() => void} callback - 完了時コールバック
217+ * @constructor
218+ * @public
219+ */
220+ constructor (
221+ sprite : Sprite ,
222+ callback ? : () => void
223+ ) {
224+
225+ // 初期状態設定
226+ sprite .alpha = 0 ;
227+
228+ // アニメーション設定
229+ this ._job = Tween .add (sprite ,
230+ {
231+ " alpha" : 0
232+ },
233+ {
234+ " alpha" : 1
235+ }, 0.5 , 1 , Easing .outQuad
236+ );
237+
238+ // 完了時コールバック
239+ if (callback ) {
240+ this ._job .addEventListener (Event .COMPLETE , callback );
241+ }
242+ }
243+
244+ /**
245+ * @description アニメーション開始
246+ * Start animation
247+ *
248+ * @method
249+ * @public
250+ */
251+ start(): void {
252+ this ._job .start ();
253+ }
254+ }
175255```
176256
177257## ベストプラクティス / Best Practices
178258
1792591 . ** 分離** - アニメーションロジックをコンポーネントから分離
180- 2 . ** 命名** - ` {Component}{Action}Animation.ts ` の形式で命名
181- 3 . ** コールバック** - 完了時の処理をサポート
182- 4 . ** 再利用** - 汎用的なアニメーションは共通化
260+ 2 . ** 命名** - ` {Component}{Action}Animation.ts ` の形式で命名(例: TopBtnShowAnimation.ts)
261+ 3 . ** コールバック** - Event.COMPLETEで完了時の処理をサポート
262+ 4 . ** 再利用** - 汎用的なアニメーションクラスは共通化
263+ 5 . ** クラスベース** - Jobインスタンスを保持し、start()メソッドで開始
183264
184265## 関連ドキュメント / Related Documentation
185266
0 commit comments