Skip to content

Commit

Permalink
fix: camera
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelBarbosatec committed Dec 21, 2024
1 parent 0eeccfa commit aa0e655
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# next
- Update `a_star_algorithm`.
- InitialMapZoomFitEnum improvements

# 3.12.4
- Switched to declarative mode to apply Grandle plugins
Expand Down
6 changes: 4 additions & 2 deletions example/lib/pages/map/spritefusion/spritefusion_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class SpritefusionPage extends StatelessWidget {
WorldMapReader.fromAsset('spritefusion/map.json'),
),
cameraConfig: CameraConfig(
zoom: getZoomFromMaxVisibleTile(context, tileSize, 20),
initPosition: Vector2(tileSize * 5, tileSize * 5),
// zoom: getZoomFromMaxVisibleTile(context, tileSize, 20),
// initPosition: Vector2(tileSize * 5, tileSize * 5),
initialMapZoomFit: InitialMapZoomFitEnum.fit,
moveOnlyMapArea: true,
),
);
}
Expand Down
17 changes: 7 additions & 10 deletions lib/camera/bonfire_camera.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:math';

import 'package:bonfire/bonfire.dart';
import 'package:bonfire/camera/camera_effects.dart';
import 'package:flame/experimental.dart';
Expand Down Expand Up @@ -76,7 +74,7 @@ class BonfireCamera extends CameraComponent with BonfireHasGameRef {
Function()? onComplete,
}) {
stop();
var controller = effectController ?? EffectController(duration: 1);
final controller = effectController ?? EffectController(duration: 1);
final moveToEffect = MoveToEffect(
position,
controller,
Expand Down Expand Up @@ -216,7 +214,7 @@ class BonfireCamera extends CameraComponent with BonfireHasGameRef {

set mapZoomFit(InitialMapZoomFitEnum value) {
config.initialMapZoomFit = value;
Vector2 sizeScreen = canvasSize;
final sizeScreen = canvasSize;
switch (value) {
case InitialMapZoomFitEnum.none:
break;
Expand All @@ -227,12 +225,11 @@ class BonfireCamera extends CameraComponent with BonfireHasGameRef {
zoom = sizeScreen.y / gameRef.map.getMapSize().y;
break;
case InitialMapZoomFitEnum.fit:
double minScreenDimension = min(sizeScreen.x, sizeScreen.y);
double minMapDimension = max(
gameRef.map.getMapSize().x,
gameRef.map.getMapSize().y,
);
zoom = minScreenDimension / minMapDimension;
if (sizeScreen.x > sizeScreen.y) {
zoom = sizeScreen.x / gameRef.map.getMapSize().x;
} else {
zoom = sizeScreen.y / gameRef.map.getMapSize().y;
}
break;
}
}
Expand Down

0 comments on commit aa0e655

Please sign in to comment.