Back to Browse

LibGdx Tutorial: Rendering a TiledMap

2.2K views
Apr 26, 2018
18:48

In this tutorial I cover basics needed to effectively render a TiledMap in java using LibGdx. Here are the classes used: TiledMap - this class was created by LibGdx to hold all of the relevant information of a map made in Tiled. TmxMapLoader - This is used to create a TiledMap object that corresponds to a map made in Tiled. This TiledMap object is returned by the load method which is passed the file name of your .tmx map. The call looks like this: TiledMap tiledMap = new TmxMapLoader().load("TheNameOfYourMap.tmx"); OrthogonalTiledMapRenderer - This draws a TiledMap on the screen. It must be passed a view, defined as an OrthographicCamera, to render the map correctly. OrthographicCamera - This defines a 2d view of the game world. It must be updated after any changes, thus should be updated at the beginning of every frame. FitViewport - This manages a Camera (parent class of OrthographicCamera) and manipulates it so, when this camera is past to a renderer, it will render its content in a way that maintains the aspect ratio of your game, regardless of the window size. It must, therefore, be updated every frame with the dimensions of the game window obtained through the methods Gdx.graphics.getWidth() and Gdx.graphics.getHeight() . It's update method will also update the Camera it manages.

Download

0 formats

No download links available.

LibGdx Tutorial: Rendering a TiledMap | NatokHD