added SetScreen test
This commit is contained in:
@@ -9,6 +9,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
import com.darkrp2d.input.CommandStream;
|
import com.darkrp2d.input.CommandStream;
|
||||||
import com.darkrp2d.input.InputHandler;
|
import com.darkrp2d.input.InputHandler;
|
||||||
import com.darkrp2d.input.commands.Command;
|
import com.darkrp2d.input.commands.Command;
|
||||||
|
import com.darkrp2d.input.commands.MenuCommand;
|
||||||
|
import com.darkrp2d.scenes.menu.MenuScreen;
|
||||||
|
|
||||||
|
|
||||||
public class DarkRP2D extends Game {
|
public class DarkRP2D extends Game {
|
||||||
@@ -18,12 +20,11 @@ public class DarkRP2D extends Game {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
//Sets inputs
|
|
||||||
Gdx.input.setInputProcessor(new InputHandler());
|
|
||||||
|
|
||||||
|
|
||||||
font = new BitmapFont();
|
font = new BitmapFont();
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
|
|
||||||
|
//Sets inputs
|
||||||
|
Gdx.input.setInputProcessor(new InputHandler(new MenuCommand(this, new MenuScreen(this))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -34,9 +35,10 @@ public class DarkRP2D extends Game {
|
|||||||
currentCommand.execute();
|
currentCommand.execute();
|
||||||
}
|
}
|
||||||
//Render stuff
|
//Render stuff
|
||||||
super.render();
|
|
||||||
Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f);
|
Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
super.render();
|
||||||
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
GlyphLayout layout = new GlyphLayout(font, "Hello World");
|
GlyphLayout layout = new GlyphLayout(font, "Hello World");
|
||||||
font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2);
|
font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2);
|
||||||
|
|||||||
@@ -16,15 +16,22 @@ import com.darkrp2d.input.commands.*;
|
|||||||
public class InputHandler implements InputProcessor {
|
public class InputHandler implements InputProcessor {
|
||||||
|
|
||||||
Command testCommand;
|
Command testCommand;
|
||||||
|
Command menuCommand;
|
||||||
|
|
||||||
public InputHandler() {
|
|
||||||
|
|
||||||
|
public InputHandler(MenuCommand menuCommand) {
|
||||||
testCommand = new TestCommand();
|
testCommand = new TestCommand();
|
||||||
|
this.menuCommand = menuCommand;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyDown(int keycode) {
|
public boolean keyDown(int keycode) {
|
||||||
if(keycode == Input.Keys.Q) {
|
if(keycode == Input.Keys.Q) {
|
||||||
CommandStream.registerCommand(testCommand);
|
CommandStream.registerCommand(testCommand);
|
||||||
|
} else if(keycode == Input.Keys.C) {
|
||||||
|
CommandStream.registerCommand(menuCommand);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
37
core/src/com/darkrp2d/input/commands/MenuCommand.java
Normal file
37
core/src/com/darkrp2d/input/commands/MenuCommand.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.darkrp2d.input.commands;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Game;
|
||||||
|
import com.badlogic.gdx.Screen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Julian
|
||||||
|
*/
|
||||||
|
public class MenuCommand implements Command {
|
||||||
|
|
||||||
|
private Game game;
|
||||||
|
private Screen screen;
|
||||||
|
private boolean toggle = false;
|
||||||
|
|
||||||
|
public MenuCommand(Game game, Screen screen) {
|
||||||
|
this.game = game;
|
||||||
|
this.screen = screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
if(!toggle) {
|
||||||
|
toggle = true;
|
||||||
|
game.setScreen(screen);
|
||||||
|
} else {
|
||||||
|
toggle = false;
|
||||||
|
game.setScreen(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,12 +3,9 @@
|
|||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package com.darkrp2d.menu;
|
package com.darkrp2d.scenes.menu;
|
||||||
|
|
||||||
import com.badlogic.gdx.Game;
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||||
import com.darkrp2d.DarkRP2D;
|
import com.darkrp2d.DarkRP2D;
|
||||||
|
|
||||||
@@ -32,10 +29,9 @@ public class MenuScreen implements Screen{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float f) {
|
public void render(float f) {
|
||||||
Gdx.gl.glClearColor(.1f, .12f, .16f, 1);
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
||||||
game.batch.begin();
|
game.batch.begin();
|
||||||
game.font.draw(game.batch, layout, 100, 100);
|
game.font.draw(game.batch, layout, 100, 100);
|
||||||
|
game.batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Reference in New Issue
Block a user