added SetScreen test

This commit is contained in:
Gulum
2017-10-14 04:02:39 +02:00
parent 9e81340ef8
commit 5041c18a20
4 changed files with 54 additions and 12 deletions

View File

@@ -9,6 +9,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.darkrp2d.input.CommandStream;
import com.darkrp2d.input.InputHandler;
import com.darkrp2d.input.commands.Command;
import com.darkrp2d.input.commands.MenuCommand;
import com.darkrp2d.scenes.menu.MenuScreen;
public class DarkRP2D extends Game {
@@ -18,12 +20,11 @@ public class DarkRP2D extends Game {
@Override
public void create () {
//Sets inputs
Gdx.input.setInputProcessor(new InputHandler());
font = new BitmapFont();
batch = new SpriteBatch();
//Sets inputs
Gdx.input.setInputProcessor(new InputHandler(new MenuCommand(this, new MenuScreen(this))));
}
@Override
@@ -34,9 +35,10 @@ public class DarkRP2D extends Game {
currentCommand.execute();
}
//Render stuff
super.render();
Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.render();
batch.begin();
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);

View File

@@ -16,15 +16,22 @@ import com.darkrp2d.input.commands.*;
public class InputHandler implements InputProcessor {
Command testCommand;
Command menuCommand;
public InputHandler() {
public InputHandler(MenuCommand menuCommand) {
testCommand = new TestCommand();
this.menuCommand = menuCommand;
}
@Override
public boolean keyDown(int keycode) {
if(keycode == Input.Keys.Q) {
CommandStream.registerCommand(testCommand);
} else if(keycode == Input.Keys.C) {
CommandStream.registerCommand(menuCommand);
}
return true;
}

View 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);
}
}
}

View File

@@ -3,12 +3,9 @@
* To change this template file, choose Tools | Templates
* 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.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.darkrp2d.DarkRP2D;
@@ -32,10 +29,9 @@ public class MenuScreen implements Screen{
@Override
public void render(float f) {
Gdx.gl.glClearColor(.1f, .12f, .16f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
game.batch.begin();
game.font.draw(game.batch, layout, 100, 100);
game.batch.end();
}
@Override