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

Commit

Permalink
refactor: methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Mar 11, 2024
1 parent b1db380 commit 972291d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/trashy_road/lib/src/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class TrashyRoadGame extends FlameGame
return Colors.transparent;
}

@override
void onGameResize(Vector2 size) {
super.onGameResize(size);
_updateBounds();
_updateZoom();
}

@override
FutureOr<void> onLoad() async {
await super.onLoad();
Expand Down Expand Up @@ -90,10 +97,10 @@ class TrashyRoadGame extends FlameGame

_player = trashyRoadWorld.tiled.children.whereType<Player>().first;
camera.follow(_player);
_setBounds();
_updateBounds();
}

void _setBounds() {
void _updateBounds() {
final worldBounds = _trashyRoadWorld?.bounds;
if (worldBounds == null) return;

Expand All @@ -106,11 +113,8 @@ class TrashyRoadGame extends FlameGame
camera.setBounds(cameraBounds);
}

@override
void onGameResize(Vector2 size) {
super.onGameResize(size);
_setBounds();

void _updateZoom() {
final size = camera.viewport.size;
camera.viewfinder.zoom = (size.x / resolution.width) + 0.2;

final isPortrait = size.y > size.x;
Expand Down

0 comments on commit 972291d

Please sign in to comment.