thanks for stopping by to help!
Having a little trouble with OrthogonalTiledMapRenderer. I’ve got a Tiled map that is 250×250 tiles, each 16×16 pixels.
Trying to use a separate camera to draw a 320×320 pixel box (20×20 tiles) in the lower right hand corner and center the view on the player.
I’m having trouble getting the box to draw at the correct coordinates, or the correct size, (haven’t even tried centering on the player yet). I feel a little bit like I’m heading down the wrong path. Any help would be very much appreciated. Here’s my relevant code:
Creating Cameras in Game Class:
public void create() {
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();
cam = new OrthographicCamera(WIDTH,HEIGHT);
cam.setToOrtho(true, WIDTH, HEIGHT);
hudCam = new OrthographicCamera(WIDTH,HEIGHT);
hudCam.setToOrtho(true, WIDTH, HEIGHT);
miniMapCam = new OrthographicCamera(WIDTH,HEIGHT);
miniMapCam.setToOrtho(true, WIDTH, HEIGHT);
miniMapCam.update();
cam.update();
sb = new SpriteBatch();
gsm = new GameStateManager(this);
}
And then here’s where I create the tilemap:
public void createGameMap(){
//load world tile map
gameMap = new TmxMapLoader().load("maps/gamemap.tmx");
gameMapRenderer = new OrthogonalTiledMapRenderer(gameMap);
}
And finally, where I render:
public void render() {
//clear screen
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.update();
//draw sub map
subMapRenderer.setView(cam);
subMapRenderer.render();
//draw miniMap
gameMapRenderer.setView(miniMapCam.combined, 50,425,240,240);
gameMapRenderer.render();
//draw player
sb.setProjectionMatrix(cam.combined);
submarine.render(sb);
//draw hud
sb.setProjectionMatrix(hudCam.combined);
hud.render(sb);
}
And here’s the result. (Added notes and measurements for reference)
