mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-28 23:46:52 +08:00
Update min Dart constraint to 3.8, which will enable us to use the fancier collection literals. This requires bumping the min Flutter version as well: <img width="1892" height="1122" alt="image" src="https://github.com/user-attachments/assets/7c7b07fc-4d96-4987-824d-9a7133ecfb85" />
61 lines
1.7 KiB
Dart
61 lines
1.7 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/events.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flame/particles.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ParticlesInteractiveExample extends FlameGame with PanDetector {
|
|
static const description =
|
|
'An example which shows how '
|
|
'ParticleSystemComponent can be added in runtime '
|
|
'following an event, in this example, the mouse '
|
|
'dragging';
|
|
|
|
final random = Random();
|
|
final Tween<double> noise = Tween(begin: -1, end: 1);
|
|
final ColorTween colorTween;
|
|
|
|
ParticlesInteractiveExample({
|
|
required Color from,
|
|
required Color to,
|
|
required double zoom,
|
|
}) : colorTween = ColorTween(begin: from, end: to),
|
|
super(
|
|
camera: CameraComponent.withFixedResolution(
|
|
width: 400,
|
|
height: 600,
|
|
)..viewfinder.zoom = zoom,
|
|
);
|
|
|
|
@override
|
|
void onPanUpdate(DragUpdateInfo info) {
|
|
add(
|
|
ParticleSystemComponent(
|
|
position: info.eventPosition.widget,
|
|
particle: Particle.generate(
|
|
count: 40,
|
|
generator: (i) {
|
|
return AcceleratedParticle(
|
|
lifespan: 2,
|
|
speed:
|
|
Vector2(
|
|
noise.transform(random.nextDouble()),
|
|
noise.transform(random.nextDouble()),
|
|
) *
|
|
i.toDouble(),
|
|
child: CircleParticle(
|
|
radius: 2,
|
|
paint: Paint()
|
|
..color = colorTween.transform(random.nextDouble())!,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|