Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
fix: make CameraMan be relative to viewport (#323)
Browse files Browse the repository at this point in the history
* fix: make CameraMan be relative to viewport

* chore: remove unused import
  • Loading branch information
alestiago authored Mar 12, 2024
1 parent 80c6a39 commit a26aac7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/trashy_road/lib/src/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,12 @@ class TrashyRoadGame extends FlameGame
}
}

class _CameraMan extends PositionComponent {
class _CameraMan extends PositionComponent
with HasGameReference<TrashyRoadGame> {
_CameraMan({required this.actor});

final PositionComponent actor;

static final _offset = UnmodifiableVector2View(0, -200);

void _updatePosition() {
position
..setFrom(actor.position)
..add(_offset);
}

@override
FutureOr<void> onLoad() async {
await super.onLoad();
Expand All @@ -181,4 +174,10 @@ class _CameraMan extends PositionComponent {
super.update(dt);
_updatePosition();
}

void _updatePosition() {
position
..setFrom(actor.position)
..y -= game.camera.viewport.size.y / 4.25;
}
}

0 comments on commit a26aac7

Please sign in to comment.