标签:
1 package com.mygdx.usemap; 2 3 import com.badlogic.gdx.ApplicationAdapter; 4 import com.badlogic.gdx.Gdx; 5 import com.badlogic.gdx.graphics.GL20; 6 import com.badlogic.gdx.graphics.OrthographicCamera; 7 import com.badlogic.gdx.maps.tiled.TiledMap; 8 import com.badlogic.gdx.maps.tiled.TmxMapLoader; 9 import com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer; 10 /** 11 * 使用地图 12 * @author Jack(乐智) 13 * @blog dtblog.cn 14 * @qq 984137183 15 */ 16 public class MainGame extends ApplicationAdapter { 17 18 //声明地图加载器 19 private TiledMap map; 20 //声明地图渲染器 21 private OrthoCachedTiledMapRenderer renderer; 22 //声明相机 23 private OrthographicCamera camera; 24 25 @Override 26 public void create() { 27 //加载地图 28 map=new TmxMapLoader().load("test2.tmx"); 29 //实例化地图渲染器 30 renderer=new OrthoCachedTiledMapRenderer(map); 31 //实例化相机 32 camera=new OrthographicCamera(); 33 //设置相机视距 34 camera.setToOrtho(false, 576, 552); 35 } 36 37 @Override 38 public void render() { 39 //设置屏幕背景色为黑色 40 Gdx.gl.glClearColor(1, 1, 1, 1); 41 //清屏 42 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 43 //更新相机状态 44 camera.update(); 45 //渲染地图比例 46 renderer.setView(camera); 47 //渲染地图 48 renderer.render(); 49 } 50 51 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <map version="1.0" orientation="orthogonal" renderorder="right-down" width="24" height="24" tilewidth="24" tileheight="23" nextobjectid="1"> 3 <tileset firstgid="1" name="test" tilewidth="24" tileheight="23" tilecount="8" columns="8"> 4 <image source="ground248.png" width="192" height="24"/> 5 </tileset> 6 <tileset firstgid="9" name="2" tilewidth="24" tileheight="23" tilecount="8" columns="8"> 7 <image source="ground288.png" width="192" height="24"/> 8 </tileset> 9 <layer name="块层 1" width="24" height="24"> 10 <data encoding="base64" compression="zlib"> 11 eJxjZGBgYBzhmJ0EtcxAzEJDt7ACMdsgCJNRPHCYlmkMlNZhaYyUdE+OPfQIKyYamsuEZD4TkXbB4o5QHDLhwMTGHb5ygljzBmO4D3U8EuoHeuVtemAALkgCuw== 12 </data> 13 </layer> 14 </map>
【开源java游戏框架libgdx专题】-13-开发工具-地图的使用
标签:
原文地址:http://www.cnblogs.com/AIThink/p/5932459.html