Last active
October 6, 2018 04:40
-
-
Save BenMcLean/566739c48ac2a73457556ec35314625b to your computer and use it in GitHub Desktop.
Simple libGDX app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; | |
import com.badlogic.gdx.graphics.Color; | |
import com.badlogic.gdx.graphics.GL20; | |
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.viewport.FitViewport; | |
import com.badlogic.gdx.utils.viewport.Viewport; | |
public class TestApp extends ApplicationAdapter { | |
public static final int width = 1280; | |
public static final int height = 720; | |
protected SpriteBatch batch; | |
protected Viewport view; | |
protected BitmapFont font; | |
@Override | |
public void create() { | |
batch = new SpriteBatch(); | |
view = new FitViewport(width, height); | |
font = new BitmapFont(); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(0, 0, 0, 0); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
view.getCamera().position.set(width / 2, height / 2, 0); | |
view.update(width, height); | |
batch.setProjectionMatrix(view.getCamera().combined); | |
batch.begin(); | |
font.setColor(Color.BLUE); | |
font.draw(batch, "Hello World", width / 2, height / 2); | |
batch.end(); | |
} | |
public static void main(String[] arg) { | |
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); | |
config.setTitle( "Test App"); | |
config.setWindowedMode(width, height); | |
config.setIdleFPS(10); | |
final TestApp app = new TestApp(); | |
new Lwjgl3Application(app, config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment