1
Fork 0

Make the main menu pretty, add logo

This commit is contained in:
Joshua Goins 2022-05-02 20:09:05 -04:00
parent 3c795da121
commit 3ea6035014
3 changed files with 31 additions and 7 deletions

BIN
assets/diamond.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View file

@ -4,7 +4,10 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.ScreenUtils;
import com.redstrate.watersymbol.WaterSymbol;
@ -13,13 +16,25 @@ public class MainMenuScreen implements Screen {
GlyphLayout titleLayout;
Texture logoTexture;
Texture diamondTexture;
Sprite backgroundSprite;
public MainMenuScreen(WaterSymbol game) {
this.game = game;
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
camera.setToOrtho(false, 800, 800);
titleLayout = new GlyphLayout(game.font, "WATER SYMBOL");
logoTexture = new Texture("logo.png");
diamondTexture = new Texture("diamond.png");
diamondTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
backgroundSprite = new Sprite(diamondTexture);
backgroundSprite.setColor(0.2f, 0.2f, 0.3f, 1.0f);
titleLayout = new GlyphLayout(game.font, "PRESS ANY BUTTON");
}
@Override
@ -29,15 +44,21 @@ public class MainMenuScreen implements Screen {
@Override
public void render(float delta) {
ScreenUtils.clear(0, 0, 0.2f, 1);
ScreenUtils.clear(0.02f, 0.01f, 0.2f, 1);
camera.update();
game.batch.setProjectionMatrix(camera.combined);
game.batch.begin();
game.font.draw(game.batch, titleLayout,
(camera.viewportWidth / 2) - (titleLayout.width / 2),
camera.viewportHeight / 2);
backgroundSprite.setPosition(camera.position.x - camera.viewportWidth / 2, camera.position.y - camera.viewportHeight / 2);
backgroundSprite.scroll(delta, delta);
backgroundSprite.draw(game.batch);
game.batch.draw(logoTexture, camera.position.x - (logoTexture.getWidth() / 2), camera.position.y - 40);
game.font.draw(game.batch, titleLayout, camera.position.x - (titleLayout.width / 2), camera.position.y - 60);
game.batch.end();
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
@ -48,7 +69,10 @@ public class MainMenuScreen implements Screen {
@Override
public void resize(int width, int height) {
camera.setToOrtho(false, width, height);
camera.viewportWidth = 330;
camera.viewportHeight = 330 * ((float)height / (float)width);
backgroundSprite.setSize(camera.viewportWidth, camera.viewportHeight);
}
@Override