Skip to content

Commit

Permalink
Changed camera position to allow joystick to fit properly in narrower…
Browse files Browse the repository at this point in the history
… landscape modes.
  • Loading branch information
lanceewing committed Mar 21, 2024
1 parent cab3982 commit 8041126
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
24 changes: 20 additions & 4 deletions core/src/main/java/com/agifans/agile/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ private void draw(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

// Render the AGI screen.
float cameraXOffset = 0;
float cameraYOffset = 0;
float sidePaddingWidth = 0;
if (viewportManager.isLandscape()) {
// Override default screen centering logic to allow for narrower screens, so
// that the joystick can be rendered as a decent size.
float agiScreenWidth = (viewportManager.getHeight() * 1.32f);
float agiWidthRatio = (agiScreenWidth / ADJUSTED_WIDTH);
sidePaddingWidth = ((viewportManager.getWidth() - agiScreenWidth) / 2);
if (sidePaddingWidth < 216) {
cameraXOffset = (sidePaddingWidth / agiWidthRatio);
}
} else {
float agiScreenHeight = (viewportManager.getWidth() / 1.32f);
float agiHeightRatio = (agiScreenHeight / ADJUSTED_HEIGHT);
float topPadding = ((viewportManager.getHeight() - agiScreenHeight) / 2);
cameraYOffset = (topPadding / agiHeightRatio);
}
camera.position.set((ADJUSTED_WIDTH / 2) + cameraXOffset, (ADJUSTED_HEIGHT / 2) - cameraYOffset, 0.0f);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.disableBlending();
Expand Down Expand Up @@ -331,10 +350,7 @@ private void draw(float delta) {
joyY = portraitTouchpad.getKnobPercentY();
} else {
// Landscape
int extraWidth = (int)(viewportManager.getWidth() - (viewportManager.getHeight() * 1.32));
int blackStripWidth = extraWidth / 2;
//System.out.println("blackStripWidth: " + blackStripWidth);
int joyWidth = Math.min(Math.max(blackStripWidth - 32, 96), 200);
float joyWidth = Math.min(Math.max((sidePaddingWidth * 2) - 32, 96), 200);
landscapeTouchpad.setSize(joyWidth, joyWidth);
landscapeTouchpad.getStyle().knob.setMinHeight(joyWidth * 0.6f);
landscapeTouchpad.getStyle().knob.setMinWidth(joyWidth * 0.6f);
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/com/agifans/agile/ui/ViewportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static ViewportManager getInstance() {
* @param height The new screen height.
*/
public void update(int width, int height) {
// TODO: This should ideally switch to portrait as soon as gap appears in Y direction.
portrait = (height > width);
getCurrentViewport().update(width, height, true);
}
Expand All @@ -93,6 +94,15 @@ public boolean isPortrait() {
return portrait;
}

/**
* Returns true if the orientation is currently landscape; otherwise false.
*
* @return true if the orientation is currently landscape; otherwise false.
*/
public boolean isLandscape() {
return !portrait;
}

/**
* Gets the current Camera to use when rendering UI components.
*
Expand Down

0 comments on commit 8041126

Please sign in to comment.