Started trying to get the zoomed in gave view to follow the boat.

Can easily make the boat stay put at the origin. can make it perfectly center, also weary of the weird jittery effect that is present when tracking. Tracking is active when the zoom scale is greater than 1.

#story[1121]
This commit is contained in:
Kusal Ekanayake
2017-08-13 17:02:35 +12:00
parent 2c5fddb695
commit 8ec6490627
2 changed files with 26 additions and 8 deletions
+25 -6
View File
@@ -88,15 +88,15 @@ public class GameView extends Pane {
double scaleFactor = 1;
public void zoomOut() {
scaleFactor = 0.95;
this.setScaleX(this.getScaleX() * scaleFactor);
this.setScaleY(this.getScaleY() * scaleFactor);
scaleFactor = 0.05;
this.setScaleX(this.getScaleX() - scaleFactor);
this.setScaleY(this.getScaleY() - scaleFactor);
}
public void zoomIn() {
scaleFactor = 1.05;
this.setScaleX(this.getScaleX() * scaleFactor);
this.setScaleY(this.getScaleY() * scaleFactor);
scaleFactor = 0.05;
this.setScaleX(this.getScaleX() + scaleFactor);
this.setScaleY(this.getScaleY() + scaleFactor);
}
private enum ScaleDirection {
@@ -104,6 +104,25 @@ public class GameView extends Pane {
VERTICAL
}
public void trackBoat() {
if (this.getScaleX() > 1) {
double x = boatObjects.get(playerYacht).getBoatLayoutX();
double y = boatObjects.get(playerYacht).getBoatLayoutY();
// System.out.println("x = " + x);
// System.out.println("y = " + y);
// this.setRotate(-playerYacht.getHeading());
Point2D displacementX = findScaledXY(maxLonPoint);
Point2D displacementY = findScaledXY(maxLatPoint);
this.setLayoutX(-x + 250 + canvasWidth/2);
this.setLayoutY(-y + canvasHeight/2);
} else {
this.setLayoutX(0);
this.setLayoutY(0);
}
System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutX());
System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutY());
}
public GameView () {
gameObjects = this.getChildren();
// create image view for map, bind panel size to image