There are many types of map editors that support LIBGDX, among which the more commonly used tools are the tiled map tool. The tiled is a very useful map editor. : Http://www.mapeditor.orgTiledMap class: Also known as Tile Map class, mainly used to parse the map file saved by the Maps editor. Common method: Dispose (): Destroys all textures in the current map getlayers (): Gets all the layers in the current map, the return value is maplayers type variable getproperties (): Gets all the properties of the current map, The return value is mapproperties type variable gettilesets (): Gets the map tile set, the return value is tiledmaptilesets type variable Orthogonaltiledmaprenderer class: Map renderer, Mainly responsible for map rendering work common methods: Beginrender (): Start drawing Dispose (): Destroy All Resource Objects endrender (): End drawing, the method executes getmap after all layers have been drawn () : Gets the current Tiledmap object Getspritebatch (): Gets the current map's sprite Brush Getunitscale (): Gets the drawing scale render (): Draw the map render (int[] layers) : Draw the map's development layer Setmap (Tiledmap map): Set the mapped map Setview (Matrix4 projection,float x,float y,float width,float height) : Set Line of sight Setview (Orthographiccamera camera): Set drawing camera rendertilelayer (Tiledmaptilelayer layer): Draws the specified layer code instance:
1 PackageCom.mygdx.usemap;2 3 ImportCom.badlogic.gdx.ApplicationAdapter;4 ImportCom.badlogic.gdx.Gdx;5 Importcom.badlogic.gdx.graphics.GL20;6 ImportCom.badlogic.gdx.graphics.OrthographicCamera;7 ImportCom.badlogic.gdx.maps.tiled.TiledMap;8 ImportCom.badlogic.gdx.maps.tiled.TmxMapLoader;9 ImportCom.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer;Ten /** One * Use map A * @authorJack (Le Zhi) - * @blog dtblog.cn - * @qq 984137183 the */ - Public classMaingameextendsApplicationadapter { - - //declaring the map loader + Privatetiledmap map; - //declaring a map renderer + PrivateOrthocachedtiledmaprenderer renderer; A //declaring a camera at PrivateOrthographiccamera camera; - - @Override - Public voidCreate () { - //Load Map -map=NewTmxmaploader (). Load ("TEST2.TMX"); in //instantiating the map renderer -Renderer=Neworthocachedtiledmaprenderer (map); to //Instantiate a camera +Camera=NewOrthographiccamera (); - //Set camera sight distance theCamera.settoortho (false, 576, 552); * } $ Panax Notoginseng @Override - Public voidrender () { the //set screen background color to black +Gdx.gl.glClearColor (1, 1, 1, 1); A //Clear Screen the Gdx.gl.glClear (gl20.gl_color_buffer_bit); + //Update camera Status - camera.update (); $ //Render Map Scale $ Renderer.setview (camera); - //Render Map - Renderer.render (); the } - Wuyi}
Map configuration file:
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Mapversion= "1.0"Orientation= "orthogonal"Renderorder= "Right-down"width= "+"Height= "+"Tilewidth= "+"Tileheight= "All"Nextobjectid= "1">3 <TilesetFirstgid= "1"name= "Test"Tilewidth= "+"Tileheight= "All"Tilecount= "8"Columns= "8">4 <ImageSource= "Ground248.png"width= "192"Height= "+"/>5 </Tileset>6 <TilesetFirstgid= "9"name= "2"Tilewidth= "+"Tileheight= "All"Tilecount= "8"Columns= "8">7 <ImageSource= "Ground288.png"width= "192"Height= "+"/>8 </Tileset>9 <Layername= "block Layer 1"width= "+"Height= "+">Ten <Dataencoding= "base64"Compression= "Zlib"> One ejxjzgbgybzhmj0etcxazejdt7acmdsgcjnrphcylmkmlnzhayyude+ opfqikyyamsuezd4tkxbb4o5qhdlhwmtghb5ygljzbmo4d3u8euoheuvtemaalkgcuw== A </Data> - </Layer> - </Map>
Map resource files: effects:
The original is written by Bo Master Le Zhi Editor, the copyright belongs to the Bo owner. The original address http://www.dtblog.cn/1160.html reprint please specify the source!
Open source Java Game Framework LIBGDX feature -13-development tools-use of maps