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
@@ -215,6 +215,7 @@ public class GameClient {
* Updates the position of a boat. Boat and position are given in the provided data. * Updates the position of a boat. Boat and position are given in the provided data.
*/ */
private void updatePosition(PositionUpdateData positionData) { private void updatePosition(PositionUpdateData positionData) {
raceView.getGameView().trackBoat();
if (positionData.getType() == DeviceType.YACHT_TYPE) { if (positionData.getType() == DeviceType.YACHT_TYPE) {
if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) { if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) {
Yacht yacht = allBoatsMap.get(positionData.getDeviceId()); Yacht yacht = allBoatsMap.get(positionData.getDeviceId());
@@ -306,11 +307,9 @@ public class GameClient {
//TODO Allow a zoom in and zoom out methods //TODO Allow a zoom in and zoom out methods
case Z: // zoom in case Z: // zoom in
raceView.getGameView().zoomIn(); raceView.getGameView().zoomIn();
System.out.println("Zoom in");
break; break;
case X: // zoom out case X: // zoom out
raceView.getGameView().zoomOut(); raceView.getGameView().zoomOut();
System.out.println("Zoom out");
break; break;
} }
} }
+25 -6
View File
@@ -88,15 +88,15 @@ public class GameView extends Pane {
double scaleFactor = 1; double scaleFactor = 1;
public void zoomOut() { public void zoomOut() {
scaleFactor = 0.95; scaleFactor = 0.05;
this.setScaleX(this.getScaleX() * scaleFactor); this.setScaleX(this.getScaleX() - scaleFactor);
this.setScaleY(this.getScaleY() * scaleFactor); this.setScaleY(this.getScaleY() - scaleFactor);
} }
public void zoomIn() { public void zoomIn() {
scaleFactor = 1.05; scaleFactor = 0.05;
this.setScaleX(this.getScaleX() * scaleFactor); this.setScaleX(this.getScaleX() + scaleFactor);
this.setScaleY(this.getScaleY() * scaleFactor); this.setScaleY(this.getScaleY() + scaleFactor);
} }
private enum ScaleDirection { private enum ScaleDirection {
@@ -104,6 +104,25 @@ public class GameView extends Pane {
VERTICAL 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 () { public GameView () {
gameObjects = this.getChildren(); gameObjects = this.getChildren();
// create image view for map, bind panel size to image // create image view for map, bind panel size to image