Skip to content

Commit

Permalink
#2 made title menu background resolution independent
Browse files Browse the repository at this point in the history
  • Loading branch information
KOTerra committed Apr 12, 2023
1 parent ba173bc commit 1bdcc28
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Binary file modified StrafeOverdead/assets/ui/backgrounds/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void render(float delta) {

shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(Color.valueOf("#40444b"));
shapeRenderer.rect(0, Gdx.graphics.getHeight() / 2f - 435 / 2f, Gdx.graphics.getWidth() * progress, 435);
float height = (Gdx.graphics.getHeight() / 1080f) * 360f;
shapeRenderer.rect(0, Gdx.graphics.getHeight() / 2f - height / 2f, Gdx.graphics.getWidth() * progress, height);
shapeRenderer.end();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ public TitleScreen(Strafer game) {
@Override
public void resize(int width, int height) {
Strafer.uiManager.getViewport().update(width, height, true);
titleMenu.resize();

}

@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Strafer.spriteBatch.begin();
Strafer.spriteBatch.draw(Strafer.assetManager.get("ui/backgrounds/banner.png", Texture.class), 0, 0);
Strafer.spriteBatch.end();
Strafer.uiManager.act(delta);
Strafer.uiManager.draw();
Strafer.uiManager.setDebugAll(Strafer.inDebug);
Expand Down
26 changes: 26 additions & 0 deletions StrafeOverdead/core/src/com/strafergame/ui/menus/TitleMenu.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package com.strafergame.ui.menus;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import com.kotcrab.vis.ui.widget.VisImage;
import com.kotcrab.vis.ui.widget.VisTextButton;
import com.strafergame.Strafer;
import com.strafergame.screens.GameScreen;
import com.strafergame.screens.SettingsScreen;

public class TitleMenu extends Table {
Strafer game;
Group background = new Group();
VisImage banner;

public TitleMenu(Strafer game) {
this.game = game;
makeBackground();

setFillParent(true);
pad(150);
defaults().space(20);
Expand All @@ -24,6 +31,14 @@ public TitleMenu(Strafer game) {
makeButtons();
}

private void makeBackground() {
banner = new VisImage(Strafer.assetManager.get("ui/backgrounds/banner.png", Texture.class));
background.addActor(banner);
banner.setAlign(Align.center);
Strafer.uiManager.addActor(background);

}

private void makeButtons() {
VisTextButton loadGameButton = new VisTextButton(Strafer.i18n.get("playButton"));
loadGameButton.addListener(new ChangeListener() {
Expand Down Expand Up @@ -59,6 +74,17 @@ public void changed(ChangeEvent event, Actor actor) {

}

@Override
public void setVisible(boolean a) {
super.setVisible(a);
background.setVisible(a);
}

public void resize() {
background.setBounds(0, 0, Strafer.uiManager.getWidth(), Strafer.uiManager.getHeight());
banner.setScale(background.getHeight() / banner.getHeight());
}

private void showLoadGameMenu() {
if (Strafer.gameScreen == null) {
Strafer.gameScreen = new GameScreen(game);
Expand Down
Binary file modified StrafeOverdead/desktop/assets/ui/backgrounds/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1bdcc28

Please sign in to comment.