Show pause menu on back key press (Android)

This commit is contained in:
Lonami Exo 2017-01-28 18:17:37 +01:00
parent 9eaba524bd
commit c47227d592
4 changed files with 11 additions and 9 deletions

View file

@ -32,6 +32,7 @@ public class Klooni extends Game {
skin.add("replay_texture", new Texture(Gdx.files.internal("ui/replay.png")));
skin.add("share_texture", new Texture(Gdx.files.internal("ui/share.png")));
Gdx.input.setCatchBackKey(true); // To show the pause menu
setScreen(new MainMenuScreen(this));
}

View file

@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -25,12 +24,9 @@ public class GameScreen implements Screen, InputProcessor {
private SpriteBatch batch;
private final Color clearColor;
private final PauseMenuStage pauseMenu;
GameScreen(final Klooni game) {
clearColor = new Color(0.9f, 0.9f, 0.7f, 1f);
batch = new SpriteBatch();
layout = new GameLayout();
@ -38,7 +34,6 @@ public class GameScreen implements Screen, InputProcessor {
scorer = new Scorer(layout, 10);
board = new Board(layout, 10);
holder = new PieceHolder(layout, 3);
pauseMenu = new PauseMenuStage(layout, game, scorer);
}
@ -60,7 +55,7 @@ public class GameScreen implements Screen, InputProcessor {
@Override
public void render(float delta) {
Gdx.gl.glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
Gdx.gl.glClearColor(0.9f, 0.9f, 0.9f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
@ -114,7 +109,7 @@ public class GameScreen implements Screen, InputProcessor {
@Override
public boolean keyUp(int keycode) {
if (keycode == Input.Keys.P) // Pause
if (keycode == Input.Keys.P || keycode == Input.Keys.BACK) // Pause
pauseMenu.show(false);
return false;

View file

@ -1,11 +1,13 @@
package io.github.lonamiwebs.klooni.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
@ -13,7 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import io.github.lonamiwebs.klooni.Klooni;
public class MainMenuScreen implements Screen {
public class MainMenuScreen extends InputListener implements Screen {
private Klooni game;
Stage stage;
@ -88,6 +90,10 @@ public class MainMenuScreen implements Screen {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Math.min(Gdx.graphics.getDeltaTime(), minDelta));
stage.draw();
if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
Gdx.app.exit();
}
}
@Override

View file

@ -158,7 +158,7 @@ public class PauseMenuStage extends Stage {
@Override
public boolean keyUp(int keyCode) {
if (keyCode == Input.Keys.P) // Pause
if (keyCode == Input.Keys.P || keyCode == Input.Keys.BACK) // Pause
hide();
return super.keyUp(keyCode);