|
|
@ -1,20 +1,28 @@
|
|
|
|
// ignore_for_file: public_member_api_docs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame/flame.dart';
|
|
|
|
import 'package:flame/flame.dart';
|
|
|
|
import 'package:flame/sprite.dart';
|
|
|
|
import 'package:flame/sprite.dart';
|
|
|
|
import 'package:flame/widgets.dart';
|
|
|
|
import 'package:flame/widgets.dart';
|
|
|
|
import 'package:flutter/material.dart' hide Image;
|
|
|
|
import 'package:flutter/material.dart' hide Image;
|
|
|
|
import 'package:pinball/gen/gen.dart';
|
|
|
|
import 'package:pinball/gen/gen.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template star_animation}
|
|
|
|
|
|
|
|
/// Widget to display a looped the star animation.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// For animation is using [SpriteAnimationWidget].
|
|
|
|
|
|
|
|
/// {@endtemplate}
|
|
|
|
class StarAnimation extends StatelessWidget {
|
|
|
|
class StarAnimation extends StatelessWidget {
|
|
|
|
const StarAnimation._({
|
|
|
|
const StarAnimation._({
|
|
|
|
Key? key,
|
|
|
|
Key? key,
|
|
|
|
required this.imagePath,
|
|
|
|
required String imagePath,
|
|
|
|
required this.columns,
|
|
|
|
required int columns,
|
|
|
|
required this.rows,
|
|
|
|
required int rows,
|
|
|
|
required this.stepTime,
|
|
|
|
required double stepTime,
|
|
|
|
}) : super(key: key);
|
|
|
|
}) : _imagePath = imagePath,
|
|
|
|
|
|
|
|
_columns = columns,
|
|
|
|
|
|
|
|
_rows = rows,
|
|
|
|
|
|
|
|
_stepTime = stepTime,
|
|
|
|
|
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// [Widget] that displays the star A animation.
|
|
|
|
StarAnimation.starA({
|
|
|
|
StarAnimation.starA({
|
|
|
|
Key? key,
|
|
|
|
Key? key,
|
|
|
|
}) : this._(
|
|
|
|
}) : this._(
|
|
|
@ -25,6 +33,7 @@ class StarAnimation extends StatelessWidget {
|
|
|
|
stepTime: 1 / 18,
|
|
|
|
stepTime: 1 / 18,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// [Widget] that displays the star B animation.
|
|
|
|
StarAnimation.starB({
|
|
|
|
StarAnimation.starB({
|
|
|
|
Key? key,
|
|
|
|
Key? key,
|
|
|
|
}) : this._(
|
|
|
|
}) : this._(
|
|
|
@ -35,6 +44,7 @@ class StarAnimation extends StatelessWidget {
|
|
|
|
stepTime: 1 / 36,
|
|
|
|
stepTime: 1 / 36,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// [Widget] that displays the star C animation.
|
|
|
|
StarAnimation.starC({
|
|
|
|
StarAnimation.starC({
|
|
|
|
Key? key,
|
|
|
|
Key? key,
|
|
|
|
}) : this._(
|
|
|
|
}) : this._(
|
|
|
@ -45,11 +55,12 @@ class StarAnimation extends StatelessWidget {
|
|
|
|
stepTime: 1 / 24,
|
|
|
|
stepTime: 1 / 24,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
final String imagePath;
|
|
|
|
final String _imagePath;
|
|
|
|
final int columns;
|
|
|
|
final int _columns;
|
|
|
|
final int rows;
|
|
|
|
final int _rows;
|
|
|
|
final double stepTime;
|
|
|
|
final double _stepTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns a list of assets to be loaded
|
|
|
|
static Future<void> loadAssets() {
|
|
|
|
static Future<void> loadAssets() {
|
|
|
|
Flame.images.prefix = '';
|
|
|
|
Flame.images.prefix = '';
|
|
|
|
|
|
|
|
|
|
|
@ -63,13 +74,13 @@ class StarAnimation extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final spriteSheet = SpriteSheet.fromColumnsAndRows(
|
|
|
|
final spriteSheet = SpriteSheet.fromColumnsAndRows(
|
|
|
|
image: Flame.images.fromCache(imagePath),
|
|
|
|
image: Flame.images.fromCache(_imagePath),
|
|
|
|
columns: columns,
|
|
|
|
columns: _columns,
|
|
|
|
rows: rows,
|
|
|
|
rows: _rows,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final animation = spriteSheet.createAnimation(
|
|
|
|
final animation = spriteSheet.createAnimation(
|
|
|
|
row: 0,
|
|
|
|
row: 0,
|
|
|
|
stepTime: stepTime,
|
|
|
|
stepTime: _stepTime,
|
|
|
|
to: spriteSheet.rows * spriteSheet.columns,
|
|
|
|
to: spriteSheet.rows * spriteSheet.columns,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|