mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
feat: SpawnComponent (#2709)
This PR introduces the `SpawnComponent`, which randomly spawns components within a set area.
This commit is contained in:
@ -4,6 +4,7 @@ import 'dart:ui';
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/effects.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/geometry.dart';
|
||||
import 'package:flutter/animation.dart';
|
||||
|
||||
class RotateEffectExample extends FlameGame {
|
||||
@ -45,7 +46,7 @@ class RotateEffectExample extends FlameGame {
|
||||
compass.arrow
|
||||
..add(
|
||||
RotateEffect.to(
|
||||
Transform2D.tau,
|
||||
tau,
|
||||
EffectController(
|
||||
duration: 20,
|
||||
infinite: true,
|
||||
@ -54,7 +55,7 @@ class RotateEffectExample extends FlameGame {
|
||||
)
|
||||
..add(
|
||||
RotateEffect.by(
|
||||
Transform2D.tau * 0.015,
|
||||
tau * 0.015,
|
||||
EffectController(
|
||||
duration: 0.1,
|
||||
reverseDuration: 0.1,
|
||||
@ -64,7 +65,7 @@ class RotateEffectExample extends FlameGame {
|
||||
)
|
||||
..add(
|
||||
RotateEffect.by(
|
||||
Transform2D.tau * 0.021,
|
||||
tau * 0.021,
|
||||
EffectController(
|
||||
duration: 0.13,
|
||||
reverseDuration: 0.13,
|
||||
@ -98,7 +99,7 @@ class Compass extends PositionComponent {
|
||||
Future<void> onLoad() async {
|
||||
_marksPath = Path();
|
||||
for (var i = 0; i < 12; i++) {
|
||||
final angle = Transform2D.tau * (i / 12);
|
||||
final angle = tau * (i / 12);
|
||||
// Note: rim takes up 0.1radius, so the lengths must be > than that
|
||||
final markLength = (i % 3 == 0) ? _radius * 0.2 : _radius * 0.15;
|
||||
_marksPath.moveTo(
|
||||
@ -189,7 +190,7 @@ class CompassRim extends PositionComponent {
|
||||
final innerRadius = _radius - _width;
|
||||
final midRadius = _radius - _width / 3;
|
||||
for (var i = 0; i < numberOfNotches; i++) {
|
||||
final angle = Transform2D.tau * (i / numberOfNotches);
|
||||
final angle = tau * (i / numberOfNotches);
|
||||
_marksPath.moveTo(
|
||||
_radius + innerRadius * sin(angle),
|
||||
_radius + innerRadius * cos(angle),
|
||||
|
||||
Reference in New Issue
Block a user