All components must call super

This commit is contained in:
Lukas Klingsbo
2020-10-07 09:20:28 +02:00
parent 7a29d19cc5
commit f48bf4d654
9 changed files with 12 additions and 10 deletions

View File

@ -16,10 +16,10 @@ class MyGame extends BaseGame with TapDetector {
} }
@override @override
void onTapUp(details) { void onTapUp(TapUpDetails details) {
square.addEffect(MoveEffect( square.addEffect(MoveEffect(
path: [ path: [
details.localPosition.toVector2().clone(), details.localPosition.toVector2(),
Vector2(100, 100), Vector2(100, 100),
Vector2(50, 120), Vector2(50, 120),
Vector2(200, 400), Vector2(200, 400),

View File

@ -37,6 +37,7 @@ class Player extends Component implements JoystickListener {
@override @override
void update(double dt) { void update(double dt) {
super.update(dt);
if (_move) { if (_move) {
moveFromAngle(dt); moveFromAngle(dt);
} }

View File

@ -590,6 +590,7 @@ class TrafficLightComponent extends Component {
@override @override
void update(double dt) { void update(double dt) {
super.update(dt);
colorChangeTimer.update(dt); colorChangeTimer.update(dt);
} }

View File

@ -1,6 +1,7 @@
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:meta/meta.dart';
import '../effects/effects.dart'; import '../effects/effects.dart';
import '../extensions/vector2.dart'; import '../extensions/vector2.dart';
@ -19,6 +20,7 @@ abstract class Component {
/// The time [t] in seconds (with microseconds precision provided by Flutter) since the last update cycle. /// The time [t] in seconds (with microseconds precision provided by Flutter) since the last update cycle.
/// This time can vary according to hardware capacity, so make sure to update your state considering this. /// This time can vary according to hardware capacity, so make sure to update your state considering this.
/// All components on [BaseGame] are always updated by the same amount. The time each one takes to update adds up to the next update cycle. /// All components on [BaseGame] are always updated by the same amount. The time each one takes to update adds up to the next update cycle.
@mustCallSuper
void update(double dt) { void update(double dt) {
_effects.forEach((e) => e.update(dt)); _effects.forEach((e) => e.update(dt));
_effects.removeWhere((e) => e.hasFinished()); _effects.removeWhere((e) => e.hasFinished());

View File

@ -65,6 +65,7 @@ class JoystickComponent extends JoystickController {
@override @override
void update(double t) { void update(double t) {
super.update(t);
directional?.update(t); directional?.update(t);
actions?.forEach((action) => action.update(t)); actions?.forEach((action) => action.update(t));
} }

View File

@ -35,6 +35,7 @@ class ParticleComponent extends Component {
/// Passes update chain to child [Particle]. /// Passes update chain to child [Particle].
@override @override
void update(double dt) { void update(double dt) {
super.update(dt);
particle.update(dt); particle.update(dt);
} }
} }

View File

@ -182,10 +182,6 @@ abstract class PositionComponent extends Component {
canvas.restore(); canvas.restore();
} }
@mustCallSuper
@override
void update(double dt) => super.update(dt);
void _renderChild(Canvas canvas, Component c) { void _renderChild(Canvas canvas, Component c) {
if (!c.loaded()) { if (!c.loaded()) {
return; return;

View File

@ -25,7 +25,4 @@ class SpriteBatchComponent extends Component {
paint: paint, paint: paint,
); );
} }
@override
void update(double t) {}
} }

View File

@ -10,7 +10,10 @@ class TimerComponent extends Component {
TimerComponent(this.timer); TimerComponent(this.timer);
@override @override
void update(double dt) => timer.update(dt); void update(double dt) {
super.update(dt);
timer.update(dt);
}
@override @override
void render(Canvas canvas) {} void render(Canvas canvas) {}