refactor: moved renderBody

pull/168/head
RuiAlonso 4 years ago
parent a9d8127355
commit 308631abc8

@ -11,7 +11,7 @@ import 'package:pinball_components/pinball_components.dart';
/// [_LaunchRampForegroundRailing]. /// [_LaunchRampForegroundRailing].
/// {@endtemplate} /// {@endtemplate}
class LaunchRamp extends Forge2DBlueprint { class LaunchRamp extends Forge2DBlueprint {
/// Base priority for ball while be in [_LaunchRampBase]. /// Base priority for [Ball] while be in [LaunchRamp].
static const ballPriorityInsideRamp = 0; static const ballPriorityInsideRamp = 0;
@override @override
@ -47,7 +47,6 @@ class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
: super( : super(
priority: LaunchRamp.ballPriorityInsideRamp - 1, priority: LaunchRamp.ballPriorityInsideRamp - 1,
) { ) {
renderBody = false;
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -154,7 +153,6 @@ class _LaunchRampForegroundRailing extends BodyComponent
: super( : super(
priority: LaunchRamp.ballPriorityInsideRamp + 1, priority: LaunchRamp.ballPriorityInsideRamp + 1,
) { ) {
renderBody = false;
layer = Layer.launcher; layer = Layer.launcher;
} }

@ -1,9 +1,11 @@
// ignore_for_file: avoid_renaming_method_parameters // ignore_for_file: avoid_renaming_method_parameters
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:pinball_components/gen/assets.gen.dart'; import 'package:pinball_components/gen/assets.gen.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets; import 'package:pinball_components/pinball_components.dart' hide Assets;
@ -14,7 +16,7 @@ class SpaceshipRail extends Forge2DBlueprint {
/// {@macro spaceship_rail} /// {@macro spaceship_rail}
SpaceshipRail(); SpaceshipRail();
/// Base priority for ball while be in [_SpaceshipRailRamp]. /// Base priority for [Ball] while be in [SpaceshipRail].
static const ballPriorityInsideRail = 2; static const ballPriorityInsideRail = 2;
@override @override
@ -47,7 +49,6 @@ class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
: super( : super(
priority: SpaceshipRail.ballPriorityInsideRail - 1, priority: SpaceshipRail.ballPriorityInsideRail - 1,
) { ) {
renderBody = false;
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
} }
@ -139,6 +140,8 @@ class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
renderBody = false;
await add(_SpaceshipRailRampSpriteComponent()); await add(_SpaceshipRailRampSpriteComponent());
} }
} }
@ -160,13 +163,6 @@ class _SpaceshipRailRampSpriteComponent extends SpriteComponent
} }
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef { class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
_SpaceshipRailForeground()
: super(
anchor: Anchor.center,
position: Vector2(-28.5, 19.7),
priority: SpaceshipRail.ballPriorityInsideRail + 1,
);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
@ -176,6 +172,9 @@ class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
); );
this.sprite = sprite; this.sprite = sprite;
size = sprite.originalSize / 10; size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(-28.5, 19.7);
priority = SpaceshipRail.ballPriorityInsideRail + 1;
} }
} }
@ -213,12 +212,14 @@ class SpaceshipRailExit extends RampOpening {
/// {@macro spaceship_rail_exit} /// {@macro spaceship_rail_exit}
SpaceshipRailExit() SpaceshipRailExit()
: super( : super(
insideLayer: Layer.spaceshipExitRail,
orientation: RampOrientation.down, orientation: RampOrientation.down,
insidePriority: 3, insideLayer: Layer.spaceshipExitRail,
insidePriority: SpaceshipRail.ballPriorityInsideRail,
) { ) {
renderBody = false;
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
paint = Paint()
..color = Colors.red
..style = PaintingStyle.fill;
} }
@override @override

@ -60,7 +60,6 @@ class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
_SpaceshipRampBackground() _SpaceshipRampBackground()
: super(priority: SpaceshipRamp.ballPriorityInsideRamp - 1) { : super(priority: SpaceshipRamp.ballPriorityInsideRamp - 1) {
renderBody = false;
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
} }
@ -152,7 +151,6 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
_SpaceshipRampForegroundRailing() _SpaceshipRampForegroundRailing()
: super(priority: SpaceshipRamp.ballPriorityInsideRamp + 1) { : super(priority: SpaceshipRamp.ballPriorityInsideRamp + 1) {
renderBody = false;
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
} }
@ -199,11 +197,13 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await add(_SpaceshipRampForegroundRalingSpriteComponent()); renderBody = false;
await add(_SpaceshipRampForegroundRailingSpriteComponent());
} }
} }
class _SpaceshipRampForegroundRalingSpriteComponent extends SpriteComponent class _SpaceshipRampForegroundRailingSpriteComponent extends SpriteComponent
with HasGameRef { with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -221,6 +221,7 @@ class _SpaceshipRampForegroundRalingSpriteComponent extends SpriteComponent
/// Represents the ground right base of the [SpaceshipRamp]. /// Represents the ground right base of the [SpaceshipRamp].
class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered { class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRampBase() { _SpaceshipRampBase() {
renderBody = false;
layer = Layer.board; layer = Layer.board;
} }

Loading…
Cancel
Save