Skip to content

Commit

Permalink
feat(flame): Set a default negative priority on the world for general…
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfenrain authored Jun 12, 2023
1 parent 3cdef95 commit 390e970
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/flame/lib/src/camera/world.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import 'package:vector_math/vector_math_64.dart';
/// The primary feature of this component is that it disables regular rendering,
/// and allows itself to be rendered through a [CameraComponent] only. The
/// updates proceed through the world tree normally.
///
/// The [priority] of the world by default is the maximum 32bit negative int
/// value to ensure it will always be earlier in the component tree than a
/// [CameraComponent].
class World extends Component implements CoordinateTransform {
World({super.children});
World({
super.children,
super.priority = -0x7fffffff,
});

@override
void renderTree(Canvas canvas) {}
Expand Down
32 changes: 32 additions & 0 deletions packages/flame/test/camera/world_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flame/camera.dart';
import 'package:flame/components.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('World', () {
testWithFlameGame(
'by default it has a negative max 32bit int priority',
(game) async {
final world = World()..addToParent(game);
final camera = CameraComponent(world: world)..addToParent(game);
await game.ready();

expect(world.priority, equals(-0x7fffffff));
expect(game.children, equals([world, camera]));
},
);

testWithFlameGame(
'with a custom priority putting it in front of the camera in the tree',
(game) async {
final world = World(priority: 4)..addToParent(game);
final camera = CameraComponent(world: world)..addToParent(game);
await game.ready();

expect(world.priority, equals(4));
expect(game.children, equals([camera, world]));
},
);
});
}

0 comments on commit 390e970

Please sign in to comment.