create animateZoom and fix map not rendering on zoom chagne
MODIFY
lib/map/map_world.dart
lib/map/map_world.dart
@@ -8,6 +8,7 @@ import 'package:flutter/cupertino.dart';
class MapWorld extends MapGame {
double lastCameraX = -1;
double lastCameraY = -1;
+ double lastZoom = -1;
Size lastSizeScreen;
Iterable<Tile> _tilesToRender = List();
Iterable<Tile> _tilesCollisionsRendered = List();
@@ -25,9 +26,11 @@ class MapWorld extends MapGame {
@override
void update(double t) {
if (lastCameraX != gameRef.gameCamera.position.x ||
- gameRef.gameCamera.position.y != lastCameraY) {
+ lastCameraY != gameRef.gameCamera.position.y ||
+ lastZoom != gameRef.gameCamera.zoom) {
lastCameraX = gameRef.gameCamera.position.x;
lastCameraY = gameRef.gameCamera.position.y;
+ lastZoom = gameRef.gameCamera.zoom;
List<Tile> tilesRender = List();
List<Tile> tilesCollision = List();
@@ -71,6 +74,7 @@ class MapWorld extends MapGame {
lastCameraX = -1;
lastCameraY = -1;
+ lastZoom = -1;
mapSize = getMapSize();
gameRef.gameCamera.moveToPlayer(horizontal: 0, vertical: 0);
}
@@ -79,6 +83,7 @@ class MapWorld extends MapGame {
void updateTiles(Iterable<Tile> map) {
lastCameraX = -1;
lastCameraY = -1;
+ lastZoom = -1;
lastSizeScreen = null;
this.tiles = map;
verifyMaxTopAndLeft(gameRef.size);

MODIFY
lib/util/camera.dart
lib/util/camera.dart
@@ -128,6 +128,27 @@ class Camera with HasGameRef<RPGGame> {
gameRef.player.focusCamera = true;
}
+ void animateZoom({
+ double zoom,
+ Duration duration,
+ VoidCallback finish,
+ Curve curve = Curves.decelerate,
+ }) {
+ if (gameRef?.size == null) return;
+ if (zoom <= 0.0) return;
+
+ double diffZoom = this.zoom - (zoom);
+ double initialZoom = this.zoom;
+
+ gameRef.getValueGenerator(duration ?? Duration(seconds: 1))
+ ..addListenerValue((value) {
+ this.zoom = initialZoom - (diffZoom * value);
+ })
+ ..addListenerFinish(finish)
+ ..addCurve(curve)
+ ..start();
+ }
+
bool isComponentOnCamera(GameComponent c) {
if (gameRef?.size == null || c.position == null) return false;

create animateZoom and fix map not rendering on zoom chagne