It’s pretty annoying to browse Java code on GitHub because of all the subfolders. I do not know libgdx
at all, but maybe I can help with architectural concerns.
The tutorials sample code is pretty simple: there’s a render()
method and a few callbacks for user interaction, and that’s it for the first part.
Implement InputProcessor
someplace else, I guess you end up with create()
and render()
waiting to be implemented. If the ApplicationAdapter
(which I assume exposes these methods) is some kind of overall game loop handler, simply delegate rendering the tile map to a TileMapController
, say.
Extracting this should be trivial:
public class TiledTest extends ApplicationAdapter implements InputProcessor {
// ...
@Override
public void create () {
// ... keep setup here
}
@Override
public void render () {
// Maybe consider clearing the back buffer in a separate Renderer
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
tileMapController.render()
}
// ...
}
class TileMapController {
OrthographicCamera camera;
TiledMapRenderer tiledMapRenderer;
public void render() {
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
}
}
Now here’s the price question: do you consider this a controller, or is this part of the view already?
I don’t think MVC is a good starting point for application architecture; it works well on a per-component basis, i.e. having a PlayerCharacter
as model, with health stats perhaps, a PlayerSprite
view component which is visible on screen, and a PlayerController
which exposes movement methods which are called by some InputProcessor
(which in turn reacts to key presses).
Starting from this point, where exactly do you experience problems in code?