Center hub on start and when pressing the home key

This commit is contained in:
Stone_Red
2022-06-02 18:53:31 +02:00
parent 5d1b6247d4
commit 084869401e
@@ -36,8 +36,8 @@ public class PlayerManager {
scene.heightProperty().addListener((e) -> redrawChunks()); scene.heightProperty().addListener((e) -> redrawChunks());
world.setOnMouseClicked(this::processClick); world.setOnMouseClicked(this::processClick);
world.setTranslateX(GameManager.START_POSITION.x); world.setTranslateX(GameManager.START_POSITION.x + world.getScene().getWidth() / 2 + 100);
world.setTranslateY(GameManager.START_POSITION.y); world.setTranslateY(GameManager.START_POSITION.y + world.getScene().getHeight() / 2 + 100);
world.setOnMouseMoved((mouse) -> currentMousePosition = new Coordinate((int) mouse.getX(), (int) mouse.getY())); world.setOnMouseMoved((mouse) -> currentMousePosition = new Coordinate((int) mouse.getX(), (int) mouse.getY()));
redrawChunks(); redrawChunks();
@@ -83,8 +83,8 @@ public class PlayerManager {
private void processKeyRelease(KeyEvent key) { private void processKeyRelease(KeyEvent key) {
if (HOME_KEY.match(key)) { if (HOME_KEY.match(key)) {
world.setTranslateX(GameManager.START_POSITION.x); world.setTranslateX(GameManager.START_POSITION.x + world.getScene().getWidth() / 2 + 100);
world.setTranslateY(GameManager.START_POSITION.y); world.setTranslateY(GameManager.START_POSITION.y + world.getScene().getHeight() / 2 + 100);
redrawChunks(); redrawChunks();
} }
} }
@@ -111,7 +111,7 @@ public class PlayerManager {
} }
Size preferredAmountOfChunks = getPreferredAmountOfChunks(); Size preferredAmountOfChunks = getPreferredAmountOfChunks();
Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate(((int) world.getTranslateX()), ((int) world.getTranslateY()))); Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate((int) world.getTranslateX() + 100, (int) world.getTranslateY() + 100));
if (chunkPosition.x < chunkPos.x) { if (chunkPosition.x < chunkPos.x) {
for (int i = 0; i < preferredAmountOfChunks.y; i++) { for (int i = 0; i < preferredAmountOfChunks.y; i++) {
@@ -146,7 +146,7 @@ public class PlayerManager {
private void redrawChunks() { private void redrawChunks() {
Size preferredAmountOfChunks = getPreferredAmountOfChunks(); Size preferredAmountOfChunks = getPreferredAmountOfChunks();
Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate(((int) world.getTranslateX()), ((int) world.getTranslateY()))); Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate((int) world.getTranslateX() + 100, (int) world.getTranslateY() + 100));
world.unloadAllChunks(); world.unloadAllChunks();