Merge branch 'main' into button
This commit is contained in:
@ -13,12 +13,26 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
public class MainMenu extends Scene {
|
public class MainMenu extends Scene {
|
||||||
private Texture backgroundTexture;
|
private Texture backgroundTexture;
|
||||||
private Texture titleTexture;
|
private Texture titleTexture;
|
||||||
|
private float titleY;
|
||||||
|
private float titleX;
|
||||||
|
private float titleWidth;
|
||||||
|
private float titleHeight;
|
||||||
|
|
||||||
public MainMenu(Game game) {
|
public MainMenu(Game game) {
|
||||||
super(game);
|
super(game);
|
||||||
backgroundTexture = Assets.getAsset("textures/main_menu/background.png", Texture.class);
|
backgroundTexture = Assets.getAsset("textures/main_menu/background.png", Texture.class);
|
||||||
titleTexture = Assets.getAsset("textures/main_menu/title.png", Texture.class);
|
titleTexture = Assets.getAsset("textures/main_menu/title.png", Texture.class);
|
||||||
|
// Scale and position title
|
||||||
|
float targetTitleWidth = 500f;
|
||||||
|
float originalWidth = titleTexture.getWidth();
|
||||||
|
float originalHeight = titleTexture.getHeight();
|
||||||
|
float scale = targetTitleWidth / originalWidth;
|
||||||
|
titleWidth = originalWidth * scale;
|
||||||
|
titleHeight = originalHeight * scale;
|
||||||
|
titleX = (WINDOW_WIDTH - titleWidth) / 2f;
|
||||||
|
titleY = WINDOW_HEIGHT / 2f - titleHeight / 8f;
|
||||||
|
|
||||||
|
// Buttons
|
||||||
var font = Assets.getFont("ui", 24);
|
var font = Assets.getFont("ui", 24);
|
||||||
UITextButton playButton = new UITextButton("Play", font);
|
UITextButton playButton = new UITextButton("Play", font);
|
||||||
UITextButton loadButton = new UITextButton("Load", font);
|
UITextButton loadButton = new UITextButton("Load", font);
|
||||||
@ -38,8 +52,9 @@ public class MainMenu extends Scene {
|
|||||||
soundButton.setPosition(20, 20);
|
soundButton.setPosition(20, 20);
|
||||||
closeButton.setPosition(WINDOW_WIDTH - 70, 20);
|
closeButton.setPosition(WINDOW_WIDTH - 70, 20);
|
||||||
|
|
||||||
int buttonWidth = 220;
|
int buttonWidth = 300;
|
||||||
int buttonHeight = 65;
|
int buttonHeight = 80;
|
||||||
|
|
||||||
playButton.setSize(buttonWidth, buttonHeight);
|
playButton.setSize(buttonWidth, buttonHeight);
|
||||||
loadButton.setSize(buttonWidth, buttonHeight);
|
loadButton.setSize(buttonWidth, buttonHeight);
|
||||||
settingsButton.setSize(buttonWidth, buttonHeight);
|
settingsButton.setSize(buttonWidth, buttonHeight);
|
||||||
@ -47,7 +62,7 @@ public class MainMenu extends Scene {
|
|||||||
|
|
||||||
int centerX = WINDOW_WIDTH / 2 - buttonWidth / 2;
|
int centerX = WINDOW_WIDTH / 2 - buttonWidth / 2;
|
||||||
int startY = WINDOW_HEIGHT / 2 - buttonHeight / 2;
|
int startY = WINDOW_HEIGHT / 2 - buttonHeight / 2;
|
||||||
int buttonSpacing = 50;
|
int buttonSpacing = 65;
|
||||||
|
|
||||||
playButton.setPosition(centerX, startY);
|
playButton.setPosition(centerX, startY);
|
||||||
loadButton.setPosition(centerX, startY - buttonSpacing);
|
loadButton.setPosition(centerX, startY - buttonSpacing);
|
||||||
@ -73,14 +88,6 @@ public class MainMenu extends Scene {
|
|||||||
@Override
|
@Override
|
||||||
public void render(SpriteBatch batch) {
|
public void render(SpriteBatch batch) {
|
||||||
batch.draw(backgroundTexture, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
batch.draw(backgroundTexture, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
float targetTitleWidth = 300f;
|
|
||||||
float originalWidth = titleTexture.getWidth();
|
|
||||||
float originalHeight = titleTexture.getHeight();
|
|
||||||
float scale = targetTitleWidth / originalWidth;
|
|
||||||
float titleWidth = originalWidth * scale;
|
|
||||||
float titleHeight = originalHeight * scale;
|
|
||||||
float titleX = (WINDOW_WIDTH - titleWidth) / 2f;
|
|
||||||
float titleY = WINDOW_HEIGHT * 0.58f;
|
|
||||||
batch.draw(titleTexture, titleX, titleY, titleWidth, titleHeight);
|
batch.draw(titleTexture, titleX, titleY, titleWidth, titleHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 238 KiB |
Reference in New Issue
Block a user