mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
zero analyzer issues
This commit is contained in:
@ -41,7 +41,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
|
|
||||||
void _clickFab(GlobalKey<ScaffoldState> key) {
|
void _clickFab(GlobalKey<ScaffoldState> key) {
|
||||||
key.currentState.showSnackBar(SnackBar(
|
key.currentState.showSnackBar(SnackBar(
|
||||||
content: Text('You clicked the FAB!'),
|
content: const Text('You clicked the FAB!'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,28 +51,28 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: key,
|
key: key,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Animation as a Widget Demo'),
|
title: const Text('Animation as a Widget Demo'),
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text('Hi there! This is a regular Flutter app,'),
|
const Text('Hi there! This is a regular Flutter app,'),
|
||||||
Text('with a complex widget tree and also'),
|
const Text('with a complex widget tree and also'),
|
||||||
Text('some pretty sprite sheet animations :)'),
|
const Text('some pretty sprite sheet animations :)'),
|
||||||
Flame.util.animationAsWidget(
|
Flame.util.animationAsWidget(
|
||||||
_position,
|
_position,
|
||||||
animation.Animation.sequenced('minotaur.png', 19,
|
animation.Animation.sequenced('minotaur.png', 19,
|
||||||
textureWidth: 96.0)),
|
textureWidth: 96.0)),
|
||||||
Text('Neat, hum?'),
|
const Text('Neat, hum?'),
|
||||||
Text('Sprites from Elthen\'s amazing work on itch.io:'),
|
const Text('Sprites from Elthen\'s amazing work on itch.io:'),
|
||||||
Text('https://elthen.itch.io/2d-pixel-art-minotaur-sprites'),
|
const Text('https://elthen.itch.io/2d-pixel-art-minotaur-sprites'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () => _clickFab(key),
|
onPressed: () => _clickFab(key),
|
||||||
child: Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:flame/animation.dart' as FlameAnimation;
|
import 'package:flame/animation.dart' as flame_animation;
|
||||||
import 'package:flame/components/animation_component.dart';
|
import 'package:flame/components/animation_component.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ class MyGame extends BaseGame {
|
|||||||
_start();
|
_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
_start() async {
|
void _start() async {
|
||||||
Size size = await Flame.util.initialDimensions();
|
final Size size = await Flame.util.initialDimensions();
|
||||||
|
|
||||||
final animation = await FlameAnimation.Animation.sequenced('chopper.png', 4,
|
final animation = flame_animation.Animation.sequenced('chopper.png', 4,
|
||||||
textureWidth: 48, textureHeight: 48, stepTime: 0.15);
|
textureWidth: 48, textureHeight: 48, stepTime: 0.15);
|
||||||
|
|
||||||
final animationComponent = AnimationComponent(100, 100, animation);
|
final animationComponent = AnimationComponent(100, 100, animation);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:flame/animation.dart' as FlameAnimation;
|
import 'package:flame/animation.dart' as flame_animation;
|
||||||
import 'package:flame/components/animation_component.dart';
|
import 'package:flame/components/animation_component.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ class MyGame extends BaseGame {
|
|||||||
_start();
|
_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
_start() async {
|
void _start() async {
|
||||||
final Size size = await Flame.util.initialDimensions();
|
final Size size = await Flame.util.initialDimensions();
|
||||||
|
|
||||||
final animation = await FlameAnimation.Animation.fromAsepriteData(
|
final animation = await flame_animation.Animation.fromAsepriteData(
|
||||||
'chopper.png', 'chopper.json');
|
'chopper.png', 'chopper.json');
|
||||||
final animationComponent = AnimationComponent(200, 200, animation);
|
final animationComponent = AnimationComponent(200, 200, animation);
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import 'package:flame/components/component.dart' show SvgComponent;
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() => runApp(MyGame());
|
void main() => runApp(MyGame().widget);
|
||||||
|
|
||||||
class MyGame extends BaseGame {
|
class MyGame extends BaseGame {
|
||||||
Svg svgInstance;
|
Svg svgInstance;
|
||||||
@ -15,7 +15,7 @@ class MyGame extends BaseGame {
|
|||||||
_start();
|
_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
_start() async {
|
void _start() {
|
||||||
svgInstance = Svg('android.svg');
|
svgInstance = Svg('android.svg');
|
||||||
android = SvgComponent.fromSvg(100, 100, svgInstance);
|
android = SvgComponent.fromSvg(100, 100, svgInstance);
|
||||||
android.x = 100;
|
android.x = 100;
|
||||||
|
|||||||
@ -16,7 +16,7 @@ TextConfig tiny = regular.withFontSize(12.0);
|
|||||||
|
|
||||||
class MyTextBox extends TextBoxComponent {
|
class MyTextBox extends TextBoxComponent {
|
||||||
MyTextBox(String text)
|
MyTextBox(String text)
|
||||||
: super(text, config: tiny, boxConfig: TextBoxConfig(timePerChar: 0.05));
|
: super(text, config: tiny, boxConfig: const TextBoxConfig(timePerChar: 0.05));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void drawBackground(Canvas c) {
|
void drawBackground(Canvas c) {
|
||||||
@ -35,7 +35,7 @@ class MyGame extends BaseGame {
|
|||||||
_start();
|
_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
_start() async {
|
void _start() async {
|
||||||
final Size size = await Flame.util.initialDimensions();
|
final Size size = await Flame.util.initialDimensions();
|
||||||
|
|
||||||
add(TextComponent('Hello, Flame', config: regular)
|
add(TextComponent('Hello, Flame', config: regular)
|
||||||
|
|||||||
@ -34,6 +34,9 @@ class Animation {
|
|||||||
/// Whether the animation loops after the last sprite of the list, going back to the first, or keeps returning the last when done.
|
/// Whether the animation loops after the last sprite of the list, going back to the first, or keeps returning the last when done.
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
|
|
||||||
|
/// Creates an animation given a list of frames.
|
||||||
|
Animation(this.frames, {this.loop = true});
|
||||||
|
|
||||||
/// Creates an empty animation
|
/// Creates an empty animation
|
||||||
Animation.empty();
|
Animation.empty();
|
||||||
|
|
||||||
@ -46,8 +49,7 @@ class Animation {
|
|||||||
frames = sprites.map((s) => Frame(s, stepTime)).toList();
|
frames = sprites.map((s) => Frame(s, stepTime)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an animation given a list of frames.
|
|
||||||
Animation(this.frames, {this.loop = true});
|
|
||||||
|
|
||||||
/// Automatically creates a sequenced animation, that is, an animation based on a sprite sheet.
|
/// Automatically creates a sequenced animation, that is, an animation based on a sprite sheet.
|
||||||
///
|
///
|
||||||
@ -156,7 +158,7 @@ class Animation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a fixed step time to all frames.
|
/// Sets a fixed step time to all frames.
|
||||||
void set stepTime(double stepTime) {
|
set stepTime(double stepTime) {
|
||||||
frames.forEach((frame) => frame.stepTime = stepTime);
|
frames.forEach((frame) => frame.stepTime = stepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import 'package:flame/box2d/box2d_component.dart';
|
|||||||
class Viewport extends ViewportTransform {
|
class Viewport extends ViewportTransform {
|
||||||
Size size;
|
Size size;
|
||||||
|
|
||||||
|
@override
|
||||||
double scale;
|
double scale;
|
||||||
|
|
||||||
Viewport(this.size, this.scale)
|
Viewport(this.size, this.scale)
|
||||||
@ -36,7 +37,7 @@ class Viewport extends ViewportTransform {
|
|||||||
///
|
///
|
||||||
/// @param screens multiplies the visible screen with to create a bigger virtual screen.
|
/// @param screens multiplies the visible screen with to create a bigger virtual screen.
|
||||||
/// @return the percentage in the range of [0, 1]
|
/// @return the percentage in the range of [0, 1]
|
||||||
double getCenterHorizontalScreenPercentage({double screens: 1.0}) {
|
double getCenterHorizontalScreenPercentage({double screens = 1.0}) {
|
||||||
final width = size.width * screens;
|
final width = size.width * screens;
|
||||||
final x = center.x + ((screens - 1) * size.width / 2);
|
final x = center.x + ((screens - 1) * size.width / 2);
|
||||||
final double rest = x.abs() % width;
|
final double rest = x.abs() % width;
|
||||||
|
|||||||
@ -20,8 +20,8 @@ class AnimationComponent extends PositionComponent {
|
|||||||
int amount, {
|
int amount, {
|
||||||
double textureX = 0.0,
|
double textureX = 0.0,
|
||||||
double textureY = 0.0,
|
double textureY = 0.0,
|
||||||
double textureWidth = null,
|
double textureWidth,
|
||||||
double textureHeight = null,
|
double textureHeight,
|
||||||
}) {
|
}) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class SpriteComponent extends PositionComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
render(Canvas canvas) {
|
void render(Canvas canvas) {
|
||||||
prepareCanvas(canvas);
|
prepareCanvas(canvas);
|
||||||
sprite.render(canvas, width, height);
|
sprite.render(canvas, width, height);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ mixin ComposedComponent on Component {
|
|||||||
OrderedSet(Comparing.on((c) => c.priority()));
|
OrderedSet(Comparing.on((c) => c.priority()));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
render(Canvas canvas) {
|
void render(Canvas canvas) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
components.forEach((comp) => _renderComponent(canvas, comp));
|
components.forEach((comp) => _renderComponent(canvas, comp));
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/src/painting/decoration_image.dart';
|
import 'package:flutter/painting.dart';
|
||||||
|
|
||||||
import '../flame.dart';
|
import '../flame.dart';
|
||||||
import 'component.dart';
|
import 'component.dart';
|
||||||
@ -48,8 +48,8 @@ class ParallaxRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class ParallaxComponent extends PositionComponent {
|
abstract class ParallaxComponent extends PositionComponent {
|
||||||
final BASE_SPEED = 30;
|
final baseSpeed = 30;
|
||||||
final LAYER_DELTA = 40;
|
final layerDelta = 40;
|
||||||
|
|
||||||
final List<ParallaxRenderer> _layers = [];
|
final List<ParallaxRenderer> _layers = [];
|
||||||
Size _size;
|
Size _size;
|
||||||
@ -108,7 +108,7 @@ abstract class ParallaxComponent extends PositionComponent {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < _layers.length; i++) {
|
for (int i = 0; i < _layers.length; i++) {
|
||||||
double scroll = _layers[i].scroll;
|
double scroll = _layers[i].scroll;
|
||||||
scroll += (BASE_SPEED + i * LAYER_DELTA) * delta / _size.width;
|
scroll += (baseSpeed + i * layerDelta) * delta / _size.width;
|
||||||
if (scroll > 1) {
|
if (scroll > 1) {
|
||||||
scroll = scroll % 1;
|
scroll = scroll % 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class Resizable {
|
|||||||
Size size;
|
Size size;
|
||||||
|
|
||||||
/// Implementation provided by this mixin to the resize hook.
|
/// Implementation provided by this mixin to the resize hook.
|
||||||
resize(Size size) {
|
void resize(Size size) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
children().where((e) => e != null).forEach((e) => e.resize(size));
|
children().where((e) => e != null).forEach((e) => e.resize(size));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,6 +126,7 @@ class TextBoxComponent extends PositionComponent with Resizable {
|
|||||||
|
|
||||||
double get currentHeight => _withMargins((currentLine + 1) * _lineHeight);
|
double get currentHeight => _withMargins((currentLine + 1) * _lineHeight);
|
||||||
|
|
||||||
|
@override
|
||||||
void render(Canvas c) {
|
void render(Canvas c) {
|
||||||
if (_cache == null) {
|
if (_cache == null) {
|
||||||
return;
|
return;
|
||||||
@ -168,6 +169,7 @@ class TextBoxComponent extends PositionComponent with Resizable {
|
|||||||
_cache = await _redrawCache();
|
_cache = await _redrawCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
final int prevCurrentChar = currentChar;
|
final int prevCurrentChar = currentChar;
|
||||||
_lifeTime += dt;
|
_lifeTime += dt;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/src/painting/text_painter.dart';
|
import 'package:flutter/painting.dart';
|
||||||
|
|
||||||
import 'component.dart';
|
import 'component.dart';
|
||||||
import '../position.dart';
|
import '../position.dart';
|
||||||
@ -10,14 +10,14 @@ class TextComponent extends PositionComponent {
|
|||||||
String _text;
|
String _text;
|
||||||
TextConfig _config;
|
TextConfig _config;
|
||||||
|
|
||||||
get text => _text;
|
String get text => _text;
|
||||||
|
|
||||||
set text(String text) {
|
set text(String text) {
|
||||||
_text = text;
|
_text = text;
|
||||||
_updateBox();
|
_updateBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
get config => _config;
|
TextConfig get config => _config;
|
||||||
|
|
||||||
set config(TextConfig config) {
|
set config(TextConfig config) {
|
||||||
_config = config;
|
_config = config;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class TiledComponent extends Component {
|
|||||||
String filename;
|
String filename;
|
||||||
TileMap map;
|
TileMap map;
|
||||||
Image image;
|
Image image;
|
||||||
Map<String, Image> images = Map<String, Image>();
|
Map<String, Image> images = <String, Image>{};
|
||||||
Future future;
|
Future future;
|
||||||
bool _loaded = false;
|
bool _loaded = false;
|
||||||
|
|
||||||
|
|||||||
@ -62,7 +62,8 @@ class FlameBiding extends BindingBase with GestureBinding, ServicesBinding {
|
|||||||
static FlameBiding instance;
|
static FlameBiding instance;
|
||||||
|
|
||||||
static FlameBiding ensureInitialized() {
|
static FlameBiding ensureInitialized() {
|
||||||
if (FlameBiding.instance == null) FlameBiding();
|
if (FlameBiding.instance == null)
|
||||||
|
FlameBiding();
|
||||||
return FlameBiding.instance;
|
return FlameBiding.instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,7 +112,9 @@ class _GameRenderBox extends RenderBox with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _tick(Duration timestamp) {
|
void _tick(Duration timestamp) {
|
||||||
if (!attached) return;
|
if (!attached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_scheduleTick();
|
_scheduleTick();
|
||||||
_update(timestamp);
|
_update(timestamp);
|
||||||
markNeedsPaint();
|
markNeedsPaint();
|
||||||
@ -166,7 +168,7 @@ abstract class BaseGame extends Game {
|
|||||||
OrderedSet(Comparing.on((c) => c.priority()));
|
OrderedSet(Comparing.on((c) => c.priority()));
|
||||||
|
|
||||||
/// Components added by the [addLater] method
|
/// Components added by the [addLater] method
|
||||||
List<Component> _addLater = [];
|
final List<Component> _addLater = [];
|
||||||
|
|
||||||
/// Current screen size, updated every resize via the [resize] method hook
|
/// Current screen size, updated every resize via the [resize] method hook
|
||||||
Size size;
|
Size size;
|
||||||
@ -175,7 +177,7 @@ abstract class BaseGame extends Game {
|
|||||||
Position camera = Position.empty();
|
Position camera = Position.empty();
|
||||||
|
|
||||||
/// List of deltas used in debug mode to calculate FPS
|
/// List of deltas used in debug mode to calculate FPS
|
||||||
List<double> _dts = [];
|
final List<double> _dts = [];
|
||||||
|
|
||||||
/// This method is called for every component added, both via [add] and [addLater] methods.
|
/// This method is called for every component added, both via [add] and [addLater] methods.
|
||||||
///
|
///
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import 'flame.dart';
|
|||||||
import 'position.dart';
|
import 'position.dart';
|
||||||
|
|
||||||
class Svg {
|
class Svg {
|
||||||
DrawableRoot svgRoot = null;
|
DrawableRoot svgRoot;
|
||||||
Size size;
|
Size size;
|
||||||
|
|
||||||
Svg(String fileName) {
|
Svg(String fileName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user