[Libgdx] This moment, with MVC architecture

Hello everyone ! I doubt that anyone would answer me, but I’ll try, it’s been several days that I search a solution, so I have nothing to lose. I’m on Libgdx (Java language) since December. So far, I was doing my levels with some arrays, placing a lot of shapes (mostly squares) everywhere. Currently, I would like to start some “real” levels.

I tried to make a Tile Map, but I can’t find any tutorial to know how to integrate the map in my engine. Really. I just found this : http://www.gamefromscratch.com/post/2014/04/15/A-quick-look-at-Tiled-An-open-source-2D-level-editor.aspx

But I have an MVC architecture, I can’t do this like this guy. My classes are divided according to the “Model-View-Controllers” organisation, I can not put everything in one class like he did ! Everything is divided among several other classes. :expressionless:

(Basically, my create() method calls my Gamescreen Class, which uses my WorldRenderer Class, which uses my World Class, which uses my Level Class which uses my arrays and the shapes to build the level. How am I suppose to act without delete everything and change the logic of my code ? :sweat:)

Here an example: https://github.com/obviam/star-assault-reboot

What I have to use to replace the world/level by my Tile Map? Do you know a good tutorial about that ? Thanks for the help, if you can help me (I hope that there are some Libgdx users around here :wink: ).

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?