Skip to content

アニメーションと演出

エンジンは、ノードのプロパティを滑らかに変化させるアニメーション機能と、画面シェイクやフラッシュなどの演出効果を提供します。

基本のアニメーション

engine.animate(id, props, config)

ノードのプロパティを指定時間かけて変化させます。await で完了を待てます。

typescript
// 移動
await engine.animate('player', { x: 300, y: 100 }, { duration: 500, easing: 'easeOutQuad' });

// フェードアウト + 拡大
await engine.animate('enemy', { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 300 });

アニメーション可能なプロパティは x, y, alpha, scaleX, scaleY, rotation, tintAmount です。

アニメーション設定

プロパティデフォルト説明
durationnumber必須持続時間(ミリ秒)
easingEasingName'easeOutQuad'イージング関数
delaynumber0開始までの遅延(ミリ秒)

イージング一覧

イージング名動き
linear等速
easeInQuadゆっくり始まる
easeOutQuadゆっくり止まる(汎用、おすすめ)
easeInOutQuadゆっくり始まってゆっくり止まる
easeInCubic / easeOutCubic / easeInOutCubicQuad より強い加減速
easeOutBack行き過ぎてから戻る(ポップイン演出に)
easeOutElasticバネのように揺れる
easeOutBounceバウンドする

TIP

迷ったら easeOutQuad を使えば大抵自然に見えます。UI のポップアップには easeOutBack が気持ちいいです。


複数アニメーションの組み合わせ

タイムライン: engine.timeline(steps)

宣言的にアニメーションの順序を記述できます。

typescript
await engine.timeline([
  // 1. 敵が左に移動
  { type: 'animate', id: 'enemy', props: { x: 100 }, config: { duration: 200 } },
  // 2. 少し待つ
  { type: 'wait', ms: 300 },
  // 3. コールバック実行
  { type: 'call', fn: () => engine.update('label', { text: 'Hit!' }) },
  // 4. 複数ノードを同時にフェードアウト
  {
    type: 'parallel',
    steps: [
      { type: 'animate', id: 'a', props: { alpha: 0 }, config: { duration: 200 } },
      { type: 'animate', id: 'b', props: { alpha: 0 }, config: { duration: 200 } },
    ],
  },
]);
ステップ type説明
animateノードアニメーション
wait指定ミリ秒の待機
call任意の関数を実行
parallel複数ステップを同時実行

順次実行: engine.sequence(...fns)

関数を順番に実行します。

typescript
await engine.sequence(
  () => engine.animate('a', { x: 100 }, { duration: 200 }),
  () => engine.animate('b', { x: 200 }, { duration: 200 }),
);

同時実行: engine.parallel(...fns)

複数の関数を同時に実行し、すべて完了するまで待ちます。

typescript
await engine.parallel(
  () => engine.animate('a', { alpha: 0 }, { duration: 200 }),
  () => engine.animate('b', { alpha: 0 }, { duration: 200 }),
);

待機: engine.wait(ms)

ゲームループに連動した待機です。

typescript
await engine.wait(500); // 500ms 待つ

画面効果

画面シェイク

被弾や爆発の際に画面を揺らす演出です。

typescript
engine.shake(); // デフォルト: 強度 8px、300ms
engine.shake(12, 500); // 強め、500ms
パラメータデフォルト説明
intensity8揺れの大きさ(px)
duration300持続時間(ms)

画面フラッシュ

撃破やダメージ時に画面を一瞬光らせます。

typescript
engine.flash(); // デフォルト: 白、200ms
engine.flash('#ef4444', 150); // 赤フラッシュ
engine.flash('#f97316', 300); // オレンジ(大爆発)
パラメータデフォルト説明
color'#fff'フラッシュの色
duration200持続時間(ms)

パーティクル

爆発や魔法のエフェクトに使えるパーティクルシステムです。

typescript
// 爆発エフェクト
engine.emitParticles({
  x: 300,
  y: 200,
  count: 15,
  colors: ['#f97316', '#ef4444', '#fbbf24'],
  speed: 150,
  lifetime: 500,
  size: 4,
});

// 上方向に噴き出す演出
engine.emitParticles({
  x: 200,
  y: 400,
  count: 20,
  colors: ['#60a5fa', '#93c5fd'],
  speed: 200,
  lifetime: 800,
  size: 3,
  direction: -Math.PI / 2, // 上方向
  spread: Math.PI * 0.5, // 90 度の扇形に拡散
  gravity: 200, // 重力で落下
});

パーティクル設定

プロパティデフォルト説明
x, ynumber必須発生位置
countnumber12パーティクル数
speednumber150初速(px/秒)
lifetimenumber600寿命(ms)
sizenumber4サイズ(px)
colorsstring[]['#fff']ランダムに選ばれる色の配列
spreadnumberMath.PI * 2拡散角度(ラジアン)
directionnumber0中心方向(ラジアン)
gravitynumber0重力(px/秒²)

INFO

directionspread を組み合わせることで、全方向に飛び散る爆発(デフォルト)や、特定方向に噴き出す演出(噴水・火柱など)を表現できます。


実践的な演出の組み合わせ例

ダメージ演出

typescript
// 赤点滅 + シェイク + パーティクル
engine.update('player', { tint: '#ff0000', tintAmount: 0.6 });
engine.shake(6, 200);
engine.emitParticles({
  x: playerX,
  y: playerY,
  count: 8,
  colors: ['#ef4444'],
  speed: 100,
  lifetime: 300,
});
await engine.animate('player', { tintAmount: 0 }, { duration: 400 });

撃破演出

typescript
// フラッシュ + パーティクル + フェードアウト
engine.flash('#fff', 100);
engine.emitParticles({
  x: enemyX,
  y: enemyY,
  count: 20,
  colors: ['#f97316', '#ef4444', '#fbbf24'],
  speed: 200,
  lifetime: 600,
});
await engine.animate('enemy', { alpha: 0, scaleX: 1.5, scaleY: 1.5 }, { duration: 300 });
engine.remove('enemy');