fix: component render order (#142)

* fix: simplify and order priorities

* test: remove position
pull/146/head
Allison Ryan 4 years ago committed by GitHub
parent c65dfb6001
commit d25643ce9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,7 +8,7 @@ import 'package:pinball_components/pinball_components.dart';
class Board extends Component { class Board extends Component {
/// {@macro board} /// {@macro board}
// TODO(alestiago): Make Board a Blueprint and sort out priorities. // TODO(alestiago): Make Board a Blueprint and sort out priorities.
Board() : super(priority: 5); Board() : super(priority: 1);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -15,7 +15,6 @@ class Plunger extends BodyComponent with KeyboardHandler, InitialPosition {
Plunger({ Plunger({
required this.compressionDistance, required this.compressionDistance,
}) : super( }) : super(
priority: 5,
// TODO(allisonryan0002): remove paint after asset is added. // TODO(allisonryan0002): remove paint after asset is added.
paint: Paint()..color = const Color.fromARGB(255, 241, 8, 8), paint: Paint()..color = const Color.fromARGB(255, 241, 8, 8),
); );

@ -35,11 +35,13 @@ class PinballGame extends Forge2DGame
_addContactCallbacks(); _addContactCallbacks();
await _addGameBoundaries(); await _addGameBoundaries();
unawaited(add(Board()));
unawaited(addFromBlueprint(Boundaries())); unawaited(addFromBlueprint(Boundaries()));
unawaited(addFromBlueprint(LaunchRamp()));
unawaited(_addPlunger()); unawaited(_addPlunger());
unawaited(add(Board()));
unawaited(addFromBlueprint(DinoWalls()));
unawaited(_addBonusWord()); unawaited(_addBonusWord());
unawaited(_addRamps()); unawaited(addFromBlueprint(SpaceshipRamp()));
unawaited( unawaited(
addFromBlueprint( addFromBlueprint(
Spaceship( Spaceship(
@ -68,13 +70,6 @@ class PinballGame extends Forge2DGame
Future<void> _addGameBoundaries() async { Future<void> _addGameBoundaries() async {
await add(BottomWall()); await add(BottomWall());
createBoundaries(this).forEach(add); createBoundaries(this).forEach(add);
unawaited(
addFromBlueprint(
DinoWalls(
position: Vector2(-2.4, 0),
),
),
);
} }
Future<void> _addPlunger() async { Future<void> _addPlunger() async {
@ -95,11 +90,6 @@ class PinballGame extends Forge2DGame
); );
} }
Future<void> _addRamps() async {
unawaited(addFromBlueprint(SpaceshipRamp()));
unawaited(addFromBlueprint(LaunchRamp()));
}
void spawnBall() { void spawnBall() {
final ball = ControlledBall.launch( final ball = ControlledBall.launch(
theme: theme, theme: theme,

@ -12,16 +12,13 @@ import 'package:pinball_components/pinball_components.dart' hide Assets;
/// {@endtemplate} /// {@endtemplate}
class DinoWalls extends Forge2DBlueprint { class DinoWalls extends Forge2DBlueprint {
/// {@macro dinowalls} /// {@macro dinowalls}
DinoWalls({required this.position}); DinoWalls();
/// The [position] where the elements will be created
final Vector2 position;
@override @override
void build(_) { void build(_) {
addAll([ addAll([
_DinoTopWall()..initialPosition = position, _DinoTopWall(),
_DinoBottomWall()..initialPosition = position, _DinoBottomWall(),
]); ]);
} }
} }
@ -31,7 +28,7 @@ class DinoWalls extends Forge2DBlueprint {
/// {@endtemplate} /// {@endtemplate}
class _DinoTopWall extends BodyComponent with InitialPosition { class _DinoTopWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoTopWall() : super(priority: 2); _DinoTopWall() : super(priority: 1);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
@ -129,7 +126,7 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
/// {@endtemplate} /// {@endtemplate}
class _DinoBottomWall extends BodyComponent with InitialPosition { class _DinoBottomWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoBottomWall() : super(priority: 2); _DinoBottomWall() : super(priority: 1);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];

@ -142,7 +142,7 @@ class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
class _LaunchRampForegroundRailing extends BodyComponent class _LaunchRampForegroundRailing extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
/// {@macro launch_ramp_foreground_railing} /// {@macro launch_ramp_foreground_railing}
_LaunchRampForegroundRailing() : super(priority: 4) { _LaunchRampForegroundRailing() : super(priority: 1) {
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -207,7 +207,6 @@ class _LaunchRampForegroundRailing extends BodyComponent
size: sprite.originalSize / 10, size: sprite.originalSize / 10,
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(22.8, 0), position: Vector2(22.8, 0),
priority: 4,
), ),
); );
} }

@ -1,6 +1,5 @@
// ignore_for_file: cascade_invocations // ignore_for_file: cascade_invocations
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart'; import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
@ -15,7 +14,7 @@ void main() {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
final dinoWalls = DinoWalls(position: Vector2.zero()); final dinoWalls = DinoWalls();
await game.addFromBlueprint(dinoWalls); await game.addFromBlueprint(dinoWalls);
await game.ready(); await game.ready();

Loading…
Cancel
Save