Use Game class, add a basic structure for main menu and game screens
This commit is contained in:
parent
fe02958e4d
commit
ca5c086189
3 changed files with 128 additions and 9 deletions
47
core/src/com/redstrate/watersymbol/GameScreen.java
Normal file
47
core/src/com/redstrate/watersymbol/GameScreen.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
|
||||
public class GameScreen implements Screen {
|
||||
private final WaterSymbol game;
|
||||
|
||||
GameScreen(WaterSymbol game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 0.2f, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
74
core/src/com/redstrate/watersymbol/MainMenuScreen.java
Normal file
74
core/src/com/redstrate/watersymbol/MainMenuScreen.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
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.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
|
||||
public class MainMenuScreen implements Screen {
|
||||
OrthographicCamera camera;
|
||||
|
||||
GlyphLayout titleLayout;
|
||||
|
||||
MainMenuScreen(WaterSymbol game) {
|
||||
this.game = game;
|
||||
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(false, 800, 480);
|
||||
|
||||
titleLayout = new GlyphLayout(game.font, "WATER SYMBOL");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 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);
|
||||
game.batch.end();
|
||||
|
||||
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
|
||||
game.setScreen(new GameScreen(game));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
camera.setToOrtho(false, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
private final WaterSymbol game;
|
||||
}
|
|
@ -1,31 +1,29 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
|
||||
public class WaterSymbol extends ApplicationAdapter {
|
||||
public class WaterSymbol extends Game {
|
||||
SpriteBatch batch;
|
||||
Texture img;
|
||||
|
||||
BitmapFont font;
|
||||
@Override
|
||||
public void create () {
|
||||
batch = new SpriteBatch();
|
||||
img = new Texture("badlogic.jpg");
|
||||
font = new BitmapFont();
|
||||
this.setScreen(new MainMenuScreen(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
ScreenUtils.clear(1, 0, 0, 1);
|
||||
batch.begin();
|
||||
batch.draw(img, 0, 0);
|
||||
batch.end();
|
||||
super.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
batch.dispose();
|
||||
img.dispose();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue