2023-07-05
HasTimeScale mixin に timeScaleというプロパティがあります。
これを使うとゲームの速度を変更することができます。
大きくすれば速く、小さくすれば遅くなります。
アニメーションは アニメーション と同じ爆発の例を使います。
HasTimeScale mixin を使用するため、withで指定します。
class TimeScaleGame extends FlameGame with HasTimeScale {
あとはボタンをクリックした時にtimeScaleを変更します。
await add(
ButtonComponent(
position: Vector2(size.x * 0.4, size.y * 0.6),
onPressed: () => timeScale *= 0.5,
button: TextComponent(
text: '* 0.5',
),
anchor: Anchor.center,
),
);
await add(
ButtonComponent(
position: Vector2(size.x * 0.6, size.y * 0.6),
onPressed: () => timeScale *= 2,
button: TextComponent(
text: '* 2',
),
anchor: Anchor.center,
),
);
これで、ゲーム速度の変更ができました。
© 2023 tnantoka