1

I am developing a top-down 2D game with a TiledMap.

Currently i want to create a minimap of my TiledMap, but i´m really confused how to do this.

I´ve read something that i should create another camera, zoom out and render the map again, but how should i draw the zoomed out map in the upper right corner?

Am i overthinking this whole thing?

My Map:

public class LiquidMap {

private TiledMap                    map;
private OrthogonalTiledMapRenderer  renderer;
private OrthographicCamera          camera = new OrthographicCamera();

private MiniMap miniMap;

public LiquidMap(String filePath) {
    map = new TmxMapLoader().load(filePath);

    renderer = new OrthogonalTiledMapRenderer(map, 1 / 32f);

    camera.setToOrtho(false, 30, 20);

    miniMap = new MiniMap(map);
}

public void update(float x, float y){
    camera.position.x = x;
    camera.position.y = y;
    camera.update();
    //renderer.setView(camera.combined, x - 10, y - 10, 20, 20);    
    renderer.setView(camera);

    miniMap.update(x, y);
}

public void update(HostPlayer player){
    this.update(player.position.x + (player.skin.getWidth()/2f)/32f, player.position.y + (player.skin.getHeight()/2f)/32f); 
}

public void render(HostPlayer player){
    renderer.render();
    renderer.getBatch().begin();
    renderer.getBatch().draw(player.skin, player.position.x, player.position.y, 1/32f * player.skin.getWidth(), 1/32f * player.skin.getHeight());
    renderer.getBatch().end();

    miniMap.render();
}

And my MiniMap:

public class MiniMap {

private OrthogonalTiledMapRenderer  renderer;
private OrthographicCamera          camera = new OrthographicCamera();

public MiniMap(TiledMap map) {

    renderer = new OrthogonalTiledMapRenderer(map, 1 / 32f);

    camera.setToOrtho(false, 30, 20);

    camera.zoom = 10;
}

public void update(){

}

public void update(float x, float y){

    //Pixventure.instance.gameScreen.getCamera()

    camera.position.x = x;
    camera.position.y = y;
    camera.update();

    renderer.setView(camera.combined, x-15, y-15, 30, 30);  
    //renderer.setView(camera); 
}

public void render(){
    renderer.render();
}

}

The whole situation is looking like this:

enter image description here

Liquidz
  • 283
  • 1
  • 4
  • 11

1 Answers1

0

Minimap's camera position is updated by player position. Place your minimap at the corner and don't change his position by your update() method.

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
  • but how can i get the minimap in the corner? if the camera position is not relative to the player, it is moving around all over the screen – Liquidz Mar 06 '17 at 09:16