refactor: renamed PinballCanvas to ZCanvas

pull/282/head
alestiago 3 years ago
parent 344568e919
commit 7d37e14969

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// The [BottomGroup] consists of [Flipper]s, [Baseboard]s and [Kicker]s. /// The [BottomGroup] consists of [Flipper]s, [Baseboard]s and [Kicker]s.
/// {@endtemplate} /// {@endtemplate}
// TODO(allisonryan0002): Consider renaming. // TODO(allisonryan0002): Consider renaming.
class BottomGroup extends Component with Rendering { class BottomGroup extends Component with ZIndex {
/// {@macro bottom_group} /// {@macro bottom_group}
BottomGroup() BottomGroup()
: super( : super(

@ -11,7 +11,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Area positioned at the top right of the board where the [Ball] can bounce /// Area positioned at the top right of the board where the [Ball] can bounce
/// off [DashNestBumper]s. /// off [DashNestBumper]s.
/// {@endtemplate} /// {@endtemplate}
class FlutterForest extends Component with Rendering { class FlutterForest extends Component with ZIndex {
/// {@macro flutter_forest} /// {@macro flutter_forest}
FlutterForest() FlutterForest()
: super( : super(

@ -8,7 +8,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template google_word} /// {@template google_word}
/// Loads all [GoogleLetter]s to compose a [GoogleWord]. /// Loads all [GoogleLetter]s to compose a [GoogleWord].
/// {@endtemplate} /// {@endtemplate}
class GoogleWord extends Component with Rendering { class GoogleWord extends Component with ZIndex {
/// {@macro google_word} /// {@macro google_word}
GoogleWord({ GoogleWord({
required Vector2 position, required Vector2 position,

@ -8,7 +8,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template multipliers} /// {@template multipliers}
/// A group for the multipliers on the board. /// A group for the multipliers on the board.
/// {@endtemplate} /// {@endtemplate}
class Multipliers extends Component with Rendering { class Multipliers extends Component with ZIndex {
/// {@macro multipliers} /// {@macro multipliers}
Multipliers() Multipliers()
: super( : super(

@ -24,7 +24,7 @@ class ScoringBehavior extends ContactBehavior with HasGameRef<PinballGame> {
gameRef.read<GameBloc>().add(Scored(points: _points)); gameRef.read<GameBloc>().add(Scored(points: _points));
gameRef.audio.score(); gameRef.audio.score();
gameRef.firstChild<PinballCanvasComponent>()?.add( gameRef.firstChild<ZCanvasComponent>()?.add(
ScoreText( ScoreText(
text: _points.toString(), text: _points.toString(),
position: other.body.position, position: other.body.position,

@ -67,7 +67,7 @@ class PinballGame extends Forge2DGame
]; ];
await add( await add(
PinballCanvasComponent( ZCanvasComponent(
children: [ children: [
...machine, ...machine,
...decals, ...decals,
@ -169,7 +169,7 @@ class _GameBallsController extends ComponentController<PinballGame>
Vector2(41.1, 43).x, Vector2(41.1, 43).x,
Vector2(41.1, 45).y - Ball.size.y, Vector2(41.1, 45).y - Ball.size.y,
); );
component.firstChild<PinballCanvasComponent>()?.add(ball); component.firstChild<ZCanvasComponent>()?.add(ball);
} }
} }
@ -197,7 +197,7 @@ class DebugPinballGame extends PinballGame with FPSCounter {
if (info.raw.kind == PointerDeviceKind.mouse) { if (info.raw.kind == PointerDeviceKind.mouse) {
final ball = ControlledBall.debug() final ball = ControlledBall.debug()
..initialPosition = info.eventPosition.game; ..initialPosition = info.eventPosition.game;
firstChild<PinballCanvasComponent>()?.add(ball); firstChild<ZCanvasComponent>()?.add(ball);
} }
} }
} }

@ -12,7 +12,7 @@ export 'cubit/android_bumper_cubit.dart';
/// {@template android_bumper} /// {@template android_bumper}
/// Bumper for area under the [AndroidSpaceship]. /// Bumper for area under the [AndroidSpaceship].
/// {@endtemplate} /// {@endtemplate}
class AndroidBumper extends BodyComponent with InitialPosition, Rendering { class AndroidBumper extends BodyComponent with InitialPosition, ZIndex {
/// {@macro android_bumper} /// {@macro android_bumper}
AndroidBumper._({ AndroidBumper._({
required double majorRadius, required double majorRadius,

@ -65,7 +65,7 @@ class _SpaceshipSaucerShape extends ChainShape {
} }
class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_SpaceshipSaucerSpriteAnimationComponent() _SpaceshipSaucerSpriteAnimationComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
@ -103,7 +103,7 @@ class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent
// TODO(allisonryan0002): add pulsing behavior. // TODO(allisonryan0002): add pulsing behavior.
class _LightBeamSpriteComponent extends SpriteComponent class _LightBeamSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_LightBeamSpriteComponent() _LightBeamSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
@ -124,8 +124,7 @@ class _LightBeamSpriteComponent extends SpriteComponent
} }
} }
class _AndroidHead extends BodyComponent class _AndroidHead extends BodyComponent with InitialPosition, Layered, ZIndex {
with InitialPosition, Layered, Rendering {
_AndroidHead() _AndroidHead()
: super( : super(
children: [_AndroidHeadSpriteAnimationComponent()], children: [_AndroidHeadSpriteAnimationComponent()],

@ -12,7 +12,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// A solid, [BodyType.dynamic] sphere that rolls and bounces around. /// A solid, [BodyType.dynamic] sphere that rolls and bounces around.
/// {@endtemplate} /// {@endtemplate}
class Ball<T extends Forge2DGame> extends BodyComponent<T> class Ball<T extends Forge2DGame> extends BodyComponent<T>
with Layered, InitialPosition, Rendering { with Layered, InitialPosition, ZIndex {
/// {@macro ball} /// {@macro ball}
Ball({ Ball({
required this.baseColor, required this.baseColor,
@ -134,7 +134,7 @@ class _BallSpriteComponent extends SpriteComponent with HasGameRef {
} }
class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_TurboChargeSpriteAnimationComponent() _TurboChargeSpriteAnimationComponent()
: super( : super(
anchor: const Anchor(0.53, 0.72), anchor: const Anchor(0.53, 0.72),

@ -5,7 +5,7 @@ import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
class BoardBackgroundSpriteComponent extends SpriteComponent class BoardBackgroundSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
BoardBackgroundSpriteComponent() BoardBackgroundSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,

@ -22,7 +22,7 @@ class Boundaries extends Component {
/// Curved boundary at the bottom of the board where the [Ball] exits the field /// Curved boundary at the bottom of the board where the [Ball] exits the field
/// of play. /// of play.
/// {@endtemplate bottom_boundary} /// {@endtemplate bottom_boundary}
class _BottomBoundary extends BodyComponent with InitialPosition, Rendering { class _BottomBoundary extends BodyComponent with InitialPosition, ZIndex {
/// {@macro bottom_boundary} /// {@macro bottom_boundary}
_BottomBoundary() _BottomBoundary()
: super( : super(
@ -90,7 +90,7 @@ class _BottomBoundarySpriteComponent extends SpriteComponent with HasGameRef {
/// The right side of the board is closed by the barrier the [LaunchRamp] /// The right side of the board is closed by the barrier the [LaunchRamp]
/// creates. /// creates.
/// {@endtemplate outer_boundary} /// {@endtemplate outer_boundary}
class _OuterBoundary extends BodyComponent with InitialPosition, Rendering { class _OuterBoundary extends BodyComponent with InitialPosition, ZIndex {
/// {@macro outer_boundary} /// {@macro outer_boundary}
_OuterBoundary() _OuterBoundary()
: super( : super(
@ -193,7 +193,7 @@ class _OuterBoundarySpriteComponent extends SpriteComponent with HasGameRef {
} }
class _OuterBottomBoundarySpriteComponent extends SpriteComponent class _OuterBottomBoundarySpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_OuterBottomBoundarySpriteComponent() _OuterBottomBoundarySpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,

@ -11,7 +11,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Upon eating a [Ball], the dino rotates and spits the [Ball] out in a /// Upon eating a [Ball], the dino rotates and spits the [Ball] out in a
/// different direction. /// different direction.
/// {@endtemplate} /// {@endtemplate}
class ChromeDino extends BodyComponent with InitialPosition, Rendering { class ChromeDino extends BodyComponent with InitialPosition, ZIndex {
/// {@macro chrome_dino} /// {@macro chrome_dino}
ChromeDino() ChromeDino()
: super( : super(

@ -23,7 +23,7 @@ class DinoWalls extends Component {
/// {@template dino_top_wall} /// {@template dino_top_wall}
/// Wall segment located above [ChromeDino]. /// Wall segment located above [ChromeDino].
/// {@endtemplate} /// {@endtemplate}
class _DinoTopWall extends BodyComponent with InitialPosition, Rendering { class _DinoTopWall extends BodyComponent with InitialPosition, ZIndex {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoTopWall() _DinoTopWall()
: super( : super(
@ -117,7 +117,7 @@ class _DinoTopWallSpriteComponent extends SpriteComponent with HasGameRef {
/// {@template dino_bottom_wall} /// {@template dino_bottom_wall}
/// Wall segment located below [ChromeDino]. /// Wall segment located below [ChromeDino].
/// {@endtemplate} /// {@endtemplate}
class _DinoBottomWall extends BodyComponent with InitialPosition, Rendering { class _DinoBottomWall extends BodyComponent with InitialPosition, ZIndex {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoBottomWall() _DinoBottomWall()
: super( : super(

@ -23,7 +23,7 @@ class LaunchRamp extends Component {
); );
} }
class _LaunchRampBase extends BodyComponent with Layered, Rendering { class _LaunchRampBase extends BodyComponent with Layered, ZIndex {
_LaunchRampBase() _LaunchRampBase()
: super( : super(
renderBody: false, renderBody: false,
@ -135,7 +135,7 @@ class _LaunchRampBackgroundRailingSpriteComponent extends SpriteComponent
} }
} }
class _LaunchRampForegroundRailing extends BodyComponent with Rendering { class _LaunchRampForegroundRailing extends BodyComponent with ZIndex {
_LaunchRampForegroundRailing() _LaunchRampForegroundRailing()
: super( : super(
children: [_LaunchRampForegroundRailingSpriteComponent()], children: [_LaunchRampForegroundRailingSpriteComponent()],

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// ///
/// [Plunger] ignores gravity so the player controls its downward [pull]. /// [Plunger] ignores gravity so the player controls its downward [pull].
/// {@endtemplate} /// {@endtemplate}
class Plunger extends BodyComponent with InitialPosition, Layered, Rendering { class Plunger extends BodyComponent with InitialPosition, Layered, ZIndex {
/// {@macro plunger} /// {@macro plunger}
Plunger({ Plunger({
required this.compressionDistance, required this.compressionDistance,

@ -6,7 +6,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template rocket_sprite_component} /// {@template rocket_sprite_component}
/// A [SpriteComponent] for the rocket over [Plunger]. /// A [SpriteComponent] for the rocket over [Plunger].
/// {@endtemplate} /// {@endtemplate}
class RocketSpriteComponent extends SpriteComponent with HasGameRef, Rendering { class RocketSpriteComponent extends SpriteComponent with HasGameRef, ZIndex {
/// {@macro rocket_sprite_component} /// {@macro rocket_sprite_component}
RocketSpriteComponent() : super(anchor: Anchor.center) { RocketSpriteComponent() : super(anchor: Anchor.center) {
zIndex = RenderPriority.rocket; zIndex = RenderPriority.rocket;

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template score_text} /// {@template score_text}
/// A [TextComponent] that spawns at a given [position] with a moving animation. /// A [TextComponent] that spawns at a given [position] with a moving animation.
/// {@endtemplate} /// {@endtemplate}
class ScoreText extends TextComponent with Rendering { class ScoreText extends TextComponent with ZIndex {
/// {@macro score_text} /// {@macro score_text}
ScoreText({ ScoreText({
required String text, required String text,

@ -6,7 +6,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template slingshots} /// {@template slingshots}
/// A collection of [Slingshot]s. /// A collection of [Slingshot]s.
/// {@endtemplate} /// {@endtemplate}
class Slingshots extends Component with Rendering { class Slingshots extends Component with ZIndex {
/// {@macro slingshots} /// {@macro slingshots}
Slingshots() Slingshots()
: super( : super(

@ -20,7 +20,7 @@ class SpaceshipRail extends Component {
); );
} }
class _SpaceshipRail extends BodyComponent with Layered, Rendering { class _SpaceshipRail extends BodyComponent with Layered, ZIndex {
_SpaceshipRail() _SpaceshipRail()
: super( : super(
children: [_SpaceshipRailSpriteComponent()], children: [_SpaceshipRailSpriteComponent()],
@ -125,7 +125,7 @@ class _SpaceshipRailSpriteComponent extends SpriteComponent with HasGameRef {
} }
class _SpaceshipRailExitSpriteComponent extends SpriteComponent class _SpaceshipRailExitSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_SpaceshipRailExitSpriteComponent() _SpaceshipRailExitSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,

@ -92,7 +92,7 @@ extension on SpaceshipRampArrowSpriteState {
} }
class _SpaceshipRampBackground extends BodyComponent class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered, Rendering { with InitialPosition, Layered, ZIndex {
_SpaceshipRampBackground() _SpaceshipRampBackground()
: super( : super(
renderBody: false, renderBody: false,
@ -146,7 +146,7 @@ class _SpaceshipRampBackground extends BodyComponent
} }
class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_SpaceshipRampBackgroundRailingSpriteComponent() _SpaceshipRampBackgroundRailingSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
@ -196,7 +196,7 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
/// {@endtemplate} /// {@endtemplate}
class _SpaceshipRampArrowSpriteComponent class _SpaceshipRampArrowSpriteComponent
extends SpriteGroupComponent<SpaceshipRampArrowSpriteState> extends SpriteGroupComponent<SpaceshipRampArrowSpriteState>
with HasGameRef, Rendering { with HasGameRef, ZIndex {
/// {@macro spaceship_ramp_arrow_sprite_component} /// {@macro spaceship_ramp_arrow_sprite_component}
_SpaceshipRampArrowSpriteComponent() _SpaceshipRampArrowSpriteComponent()
: super( : super(
@ -226,7 +226,7 @@ class _SpaceshipRampArrowSpriteComponent
} }
class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_SpaceshipRampBoardOpeningSpriteComponent() : super(anchor: Anchor.center) { _SpaceshipRampBoardOpeningSpriteComponent() : super(anchor: Anchor.center) {
zIndex = RenderPriority.spaceshipRampBoardOpening; zIndex = RenderPriority.spaceshipRampBoardOpening;
} }
@ -245,7 +245,7 @@ class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
} }
class _SpaceshipRampForegroundRailing extends BodyComponent class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered, Rendering { with InitialPosition, Layered, ZIndex {
_SpaceshipRampForegroundRailing() _SpaceshipRampForegroundRailing()
: super( : super(
renderBody: false, renderBody: false,

@ -6,7 +6,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Animated Sparky that sits on top of the [SparkyComputer]. /// Animated Sparky that sits on top of the [SparkyComputer].
/// {@endtemplate} /// {@endtemplate}
class SparkyAnimatronic extends SpriteAnimationComponent class SparkyAnimatronic extends SpriteAnimationComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
/// {@macro sparky_animatronic} /// {@macro sparky_animatronic}
SparkyAnimatronic() SparkyAnimatronic()
: super( : super(

@ -12,7 +12,7 @@ export 'cubit/sparky_bumper_cubit.dart';
/// {@template sparky_bumper} /// {@template sparky_bumper}
/// Bumper for Sparky area. /// Bumper for Sparky area.
/// {@endtemplate} /// {@endtemplate}
class SparkyBumper extends BodyComponent with InitialPosition, Rendering { class SparkyBumper extends BodyComponent with InitialPosition, ZIndex {
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
SparkyBumper._({ SparkyBumper._({
required double majorRadius, required double majorRadius,

@ -20,7 +20,7 @@ class SparkyComputer extends Component {
); );
} }
class _ComputerBase extends BodyComponent with InitialPosition, Rendering { class _ComputerBase extends BodyComponent with InitialPosition, ZIndex {
_ComputerBase() _ComputerBase()
: super( : super(
renderBody: false, renderBody: false,
@ -85,7 +85,7 @@ class _ComputerBaseSpriteComponent extends SpriteComponent with HasGameRef {
} }
class _ComputerTopSpriteComponent extends SpriteComponent class _ComputerTopSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_ComputerTopSpriteComponent() _ComputerTopSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
@ -109,7 +109,7 @@ class _ComputerTopSpriteComponent extends SpriteComponent
} }
class _ComputerGlowSpriteComponent extends SpriteComponent class _ComputerGlowSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef, ZIndex {
_ComputerGlowSpriteComponent() _ComputerGlowSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,

@ -27,7 +27,7 @@ void main() {
'renders correctly', 'renders correctly',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final canvas = PinballCanvasComponent( final canvas = ZCanvasComponent(
children: [AndroidSpaceship(position: Vector2.zero())], children: [AndroidSpaceship(position: Vector2.zero())],
); );
await game.ensureAdd(canvas); await game.ensureAdd(canvas);

@ -29,7 +29,7 @@ void main() {
'render correctly', 'render correctly',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final canvas = PinballCanvasComponent(children: [Boundaries()]); final canvas = ZCanvasComponent(children: [Boundaries()]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
game.camera.followVector2(Vector2.zero()); game.camera.followVector2(Vector2.zero());

@ -40,7 +40,7 @@ void main() {
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final component = SpaceshipRamp(); final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]); final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
await tester.pump(); await tester.pump();
@ -65,7 +65,7 @@ void main() {
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final component = SpaceshipRamp(); final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]); final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
component.progress(); component.progress();
@ -91,7 +91,7 @@ void main() {
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final component = SpaceshipRamp(); final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]); final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
component component
@ -119,7 +119,7 @@ void main() {
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final component = SpaceshipRamp(); final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]); final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
component component
@ -148,7 +148,7 @@ void main() {
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final component = SpaceshipRamp(); final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]); final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
component component
@ -178,7 +178,7 @@ void main() {
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
final component = SpaceshipRamp(); final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]); final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas); await game.ensureAdd(canvas);
component component

@ -1,3 +1,3 @@
export 'pinball_canvas.dart'; export 'z_canvas.dart';
export 'pinball_canvas_component.dart'; export 'z_canvas_component.dart';
export 'rendering_mixin.dart'; export 'z_index.dart';

@ -6,12 +6,12 @@ import 'dart:ui';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:pinball_flame/src/rendering/rendering.dart'; import 'package:pinball_flame/src/rendering/rendering.dart';
class PinballCanvas implements Canvas { class ZCanvas implements Canvas {
late Canvas canvas; late Canvas canvas;
final List<Rendering> _zBuffer = []; final List<ZIndex> _zBuffer = [];
void buffer(Rendering rendering) => _zBuffer.add(rendering); void buffer(ZIndex rendering) => _zBuffer.add(rendering);
void render() => _zBuffer void render() => _zBuffer
..sort((a, b) => a.zIndex.compareTo(b.zIndex)) ..sort((a, b) => a.zIndex.compareTo(b.zIndex))

@ -5,13 +5,13 @@ import 'dart:ui' show Canvas;
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:pinball_flame/src/rendering/rendering.dart'; import 'package:pinball_flame/src/rendering/rendering.dart';
class PinballCanvasComponent extends Component { class ZCanvasComponent extends Component {
PinballCanvasComponent({ ZCanvasComponent({
Iterable<Component>? children, Iterable<Component>? children,
}) : _pinballCanvas = PinballCanvas(), }) : _pinballCanvas = ZCanvas(),
super(children: children); super(children: children);
final PinballCanvas _pinballCanvas; final ZCanvas _pinballCanvas;
@override @override
void renderTree(Canvas canvas) { void renderTree(Canvas canvas) {

@ -4,14 +4,14 @@ import 'dart:ui';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:pinball_flame/src/rendering/rendering.dart'; import 'package:pinball_flame/src/rendering/rendering.dart';
mixin Rendering on Component { mixin ZIndex on Component {
int zIndex = 0; int zIndex = 0;
@override @override
void renderTree( void renderTree(
Canvas canvas, Canvas canvas,
) { ) {
if (canvas is PinballCanvas) { if (canvas is ZCanvas) {
canvas.buffer(this); canvas.buffer(this);
} else { } else {
super.renderTree(canvas); super.renderTree(canvas);
Loading…
Cancel
Save