Files
Pasha Stetsenko 820950dc39 CameraComponent (#933)
* Viewport and combinedProjector now belong to Camera

* cleanup

* format

* fix analysis issues

* Property viewport removed from BaseGame

* Move camera & viewport into a separate directory

* added CameraComponent

* format

* .camera as computed property

* changelog note

* format

* format

* comment

* CameraComponent is no longer a Component

* Rename CameraComponent -> CameraCo

* format

* Rename CameraC -> CameraWrapper

* minor

* rename BaseGame._cameraComponent -> ._cameraWrapper

* minor fixes in response to reviewer suggestions

* Fix rendering of a ParallaxComponent

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
2021-09-13 16:46:44 +02:00

43 lines
1.1 KiB
Dart

import 'package:flame/game.dart';
import 'package:flame_forge2d/body_component.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_forge2d/forge2d_game.dart';
import 'package:forge2d/forge2d.dart';
List<Wall> createBoundaries(Forge2DGame game) {
final topLeft = Vector2.zero();
final bottomRight = game.screenToWorld(game.camera.viewport.effectiveSize);
final topRight = Vector2(bottomRight.x, topLeft.y);
final bottomLeft = Vector2(topLeft.x, bottomRight.y);
return [
Wall(topLeft, topRight),
Wall(topRight, bottomRight),
Wall(bottomRight, bottomLeft),
Wall(bottomLeft, topLeft),
];
}
class Wall extends BodyComponent {
final Vector2 start;
final Vector2 end;
Wall(this.start, this.end);
@override
Body createBody() {
final shape = EdgeShape()..set(start, end);
final fixtureDef = FixtureDef(shape)
..restitution = 0.0
..friction = 0.3;
final bodyDef = BodyDef()
..userData = this // To be able to determine object in collision
..position = Vector2.zero()
..type = BodyType.static;
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}