com.badlogic.gdx.maps.tiled.TiledMap Java Examples
The following examples show how to use
com.badlogic.gdx.maps.tiled.TiledMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 6 votes |
protected void loadObjectGroup (TiledMap map, Element element) { if (element.getName().equals("objectgroup")) { String name = element.getAttribute("name", null); MapLayer layer = new MapLayer(); layer.setName(name); Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(layer.getProperties(), properties); } for (Element objectElement : element.getChildrenByName("object")) { loadObject(layer, objectElement); } map.getLayers().add(layer); } }
Example #2
Source File: MyNavTmxMapLoader.java From Norii with Apache License 2.0 | 6 votes |
private GridCell[][] createGridCells(TiledMap map, Element element, int width, int height) { int[] ids = getTileIds(element, width, height); TiledMapTileSets tilesets = map.getTileSets(); GridCell[][] nodes = new GridCell[width][height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int id = ids[y * width + x]; TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR); GridCell cell = new GridCell(x, height - 1 - y, false); if (tile != null) { MapProperties tileProp = tile.getProperties(); String walkableProp = tileProp.get(navigationProperty, navigationClosedValue, String.class); cell.setWalkable( !walkableProp.equals(navigationClosedValue) ); } nodes[cell.getX()][cell.getY()] = cell; } } return nodes; }
Example #3
Source File: GameLevels.java From uracer-kotd with Apache License 2.0 | 5 votes |
public static TiledMap load (String levelId) { GameLevelDescriptor desc = getLevel(levelId); if (desc != null) { String filename = desc.getFileName(); if (filename != null) { FileHandle h = Gdx.files.internal(Storage.Levels + filename); if (h.exists()) { return mapLoader.load(h.path(), mapLoaderParams); } } } return null; }
Example #4
Source File: FringeLayer.java From RuinsOfRevenge with MIT License | 5 votes |
public FringeLayer(TiledMap map, TiledMapTileLayer fringeLayer) { this.map = map; this.layer = fringeLayer; this.tiles = new ArrayList<>(); for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { TiledMapTileLayer.Cell cell = layer.getCell(x, y); if (cell == null) continue; String yoffsetStr = cell.getTile().getProperties().get("yoffset", String.class); if (yoffsetStr == null || yoffsetStr.isEmpty()) { System.out.println("Warning - Fringe tile at [" + x + ", " + y + "] missing property <yoffset>"); } else { try { tiles.add(new FringeTile( cell, x, y, Float.parseFloat(yoffsetStr))); } catch (NumberFormatException e) { System.err.println("Can't parse \"" + yoffsetStr + "\" as float: " + e); } } } } Collections.sort(tiles); }
Example #5
Source File: TmxMapLoadingTest.java From pathfinding with Apache License 2.0 | 5 votes |
@Override public void create() { TiledMap map = new NavTmxMapLoader(new ClassPathResolver()).load(tmxFile); AStarGridFinder<GridCell> finder = new AStarGridFinder<GridCell>(GridCell.class); NavigationTiledMapLayer nav = (NavigationTiledMapLayer)map.getLayers().get("navigation"); path = finder.findPath(0, 0, 9, 9, nav); loaded = true; }
Example #6
Source File: NavTmxMapLoader.java From pathfinding with Apache License 2.0 | 5 votes |
private void loadNavigationLayer(TiledMap map, Element element, String layerName){ int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int[] ids = getTileIds(element, width, height); TiledMapTileSets tilesets = map.getTileSets(); GridCell[][] nodes = new GridCell[width][height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int id = ids[y * width + x]; TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR); GridCell cell = new GridCell(x, height - 1 - y, false); if (tile != null) { MapProperties tileProp = tile.getProperties(); String walkableProp = tileProp.get(navigationProperty, navigationClosedValue, String.class); cell.setWalkable( !walkableProp.equals(navigationClosedValue) ); } nodes[cell.getX()][cell.getY()] = cell; } } NavigationTiledMapLayer layer = new NavigationTiledMapLayer(nodes); layer.setName(layerName); layer.setVisible(false); Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(layer.getProperties(), properties); } map.getLayers().add(layer); }
Example #7
Source File: NavTmxMapLoader.java From pathfinding with Apache License 2.0 | 5 votes |
@Override protected void loadTileLayer(TiledMap map, Element element) { String layerName = element.getAttribute("name", null); if ( navigationLayerName.equals(layerName)){ loadNavigationLayer(map, element, layerName); } else{ super.loadTileLayer(map, element); } }
Example #8
Source File: LevelRenderer.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
public LevelRenderer(final TiledMap map, final AssetManager assets, final Batch batch, final float unitScale) { collectibles = new Array<CollectibleRenderer>(3); Texture background = assets.get(map.getProperties().get(BACKGROUND_PROPERTY, Assets.DEFAULT_BACKGROUND.fileName, String.class), Texture.class); renderer = new BackgroundTiledMapRenderer(map, unitScale, batch, background); }
Example #9
Source File: TiledRendererSystem.java From Entitas-Java with MIT License | 5 votes |
@Override protected void execute(List<SceneEntity> gameEntities) { Tiled tiled = context.getTiled(); TiledMap tiledMap = assetsManager.getMap(tiled.tileMapName); tiledRenderer.setMap(tiledMap); tiledRenderer.setView((OrthographicCamera) cam); }
Example #10
Source File: TiledRendererSystem.java From Entitas-Java with MIT License | 5 votes |
@Override public void initialize() { this.cam = context.getCamera().camera; Tiled tiled = context.getTiled(); TiledMap tiledMap = assetsManager.getMap(tiled.tileMapName); this.tiledRenderer = new OrthogonalTiledMapRenderer(tiledMap, tiled.unitScale); }
Example #11
Source File: WorldBuilder.java From Pacman_libGdx with MIT License | 5 votes |
public WorldBuilder(TiledMap tiledMap, Engine engine, World world, RayHandler rayHandler) { this.tiledMap = tiledMap; this.engine = engine; this.world = world; this.rayHandler = rayHandler; assetManager = GameManager.instance.assetManager; actorAtlas = assetManager.get("images/actors.pack", TextureAtlas.class); }
Example #12
Source File: MyNavTmxMapLoader.java From Norii with Apache License 2.0 | 5 votes |
private void loadNavigationLayer(TiledMap map, Element element, String layerName){ int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); GridCell[][] nodes = createGridCells(map, element, width, height); MyNavigationTiledMapLayer layer = createNavigationTiledMapLayer(layerName, nodes); loadProperties(element, layer); map.getLayers().add(layer); }
Example #13
Source File: MyNavTmxMapLoader.java From Norii with Apache License 2.0 | 5 votes |
@Override protected void loadTileLayer(TiledMap map,MapLayers maplayers, Element element) { String layerName = element.getAttribute("name", null); if ( navigationLayerName.equals(layerName)){ loadNavigationLayer(map, element, layerName); } else{ super.loadTileLayer(map,maplayers, element); } }
Example #14
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
protected void loadTileLayer (TiledMap map, Element element) { if (element.getName().equals("layer")) { String name = element.getAttribute("name", null); int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int tileWidth = element.getParent().getIntAttribute("tilewidth", 0); int tileHeight = element.getParent().getIntAttribute("tileheight", 0); boolean visible = element.getIntAttribute("visible", 1) == 1; float opacity = element.getFloatAttribute("opacity", 1.0f); TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight); layer.setVisible(visible); layer.setOpacity(opacity); layer.setName(name); int[] ids = TmxMapHelper.getTileIds(element, width, height); TiledMapTileSets tilesets = map.getTileSets(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int id = ids[y * width + x]; boolean flipHorizontally = ((id & FLAG_FLIP_HORIZONTALLY) != 0); boolean flipVertically = ((id & FLAG_FLIP_VERTICALLY) != 0); boolean flipDiagonally = ((id & FLAG_FLIP_DIAGONALLY) != 0); TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR); if (tile != null) { Cell cell = createTileLayerCell(flipHorizontally, flipVertically, flipDiagonally); cell.setTile(tile); layer.setCell(x, yUp ? height - 1 - y : y, cell); } } } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(layer.getProperties(), properties); } map.getLayers().add(layer); } }
Example #15
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
@Override public TiledMap loadSync (AssetManager manager, String fileName, FileHandle file, AtlasTiledMapLoaderParameters parameter) { if (parameter != null) { setTextureFilters(parameter.textureMinFilter, parameter.textureMagFilter); } return map; }
Example #16
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
public TiledMap load (String fileName, AtlasTiledMapLoaderParameters parameter) { try { if (parameter != null) { yUp = parameter.yUp; convertObjectToTileSpace = parameter.convertObjectToTileSpace; } else { yUp = true; convertObjectToTileSpace = false; } FileHandle tmxFile = resolve(fileName); root = xml.parse(tmxFile); ObjectMap<String, TextureAtlas> atlases = new ObjectMap<String, TextureAtlas>(); FileHandle atlasFile = loadAtlas(root, tmxFile); if (atlasFile == null) { throw new GdxRuntimeException("Couldn't load atlas"); } TextureAtlas atlas = new TextureAtlas(atlasFile); atlases.put(atlasFile.path(), atlas); AtlasResolver.DirectAtlasResolver atlasResolver = new AtlasResolver.DirectAtlasResolver(atlases); TiledMap map = loadMap(root, tmxFile, atlasResolver, parameter); map.setOwnedResources(atlases.values().toArray()); setTextureFilters(parameter.textureMinFilter, parameter.textureMagFilter); return map; } catch (IOException e) { throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e); } }
Example #17
Source File: MapUtils.java From uracer-kotd with Apache License 2.0 | 5 votes |
public MapUtils (TiledMap map, int tileWidth, int mapHeight, Vector2 worldSizePx) { this.map = map; this.tileWidth = tileWidth; this.mapHeight = mapHeight; this.worldSizePx.set(worldSizePx); invTileWidth = 1f / (float)tileWidth; }
Example #18
Source File: MapManager.java From Norii with Apache License 2.0 | 4 votes |
public TiledMap getCurrentTiledMap(){ if( currentMap == null ) { loadMap(MapFactory.MapType.BATTLE_MAP); } return currentMap.getCurrentTiledMap(); }
Example #19
Source File: Map.java From Norii with Apache License 2.0 | 4 votes |
public TiledMap getCurrentTiledMap() { return currentMap; }
Example #20
Source File: Utility.java From Norii with Apache License 2.0 | 4 votes |
public static void loadMapAsset(final String mapFilenamePath) { loadAsset(mapFilenamePath, TiledMap.class, new MyNavTmxMapLoader(filePathResolver)); }
Example #21
Source File: Utility.java From Norii with Apache License 2.0 | 4 votes |
public static TiledMap getMapAsset(final String mapFilenamePath) { return (TiledMap) getAsset(mapFilenamePath, TiledMap.class); }
Example #22
Source File: AssetsManagerGDX.java From Entitas-Java with MIT License | 4 votes |
public TiledMap getMap(String name) { return assetManager.get(name); }
Example #23
Source File: BackgroundTiledMapRenderer.java From ninja-rabbit with GNU General Public License v2.0 | 4 votes |
public BackgroundTiledMapRenderer(final TiledMap map, final float unitScale, final Batch batch, final Texture background) { super(map, unitScale, batch); this.background = background; }
Example #24
Source File: LevelFactory.java From ninja-rabbit with GNU General Public License v2.0 | 4 votes |
/** * Loads a tiled map described by the given level number. Creates {@link CollectibleRenderer} * for collectible layers (every layer which name starts with "collectible"). * * @param world * The Box2D {@link World} used to create bodies and fixtures from objects layers in * the map. * @param loader * @param batch * A {@link Batch} to use while rendering tiles. * @param assets * {@link AssetManager} from where to get audio and graphics resources for the * collectibles. * @param level * Number of the level the returned render should draw. * @param unitScale * Pixels per unit. * * @return A new {@link LevelRenderer}, ready to render the map, its bodies and collectibles. */ public static LevelRenderer create(final World world, final BodyEditorLoader loader, final Batch batch, final AssetManager assets, final byte level, final float unitScale) { TiledMap tiledMap = new TmxMapLoader().load(String.format(LEVEL_MAP_FILE, level)); LevelRenderer renderer = new LevelRenderer(tiledMap, assets, batch, unitScale); for (MapLayer ml : tiledMap.getLayers()) { if (ml.getName().toLowerCase().startsWith(COLLECTIBLES_LAYER)) { CollectibleRenderer carrots = new CollectibleRenderer(unitScale); carrots.load(world, loader, assets, ml); renderer.addCollectibleRenderer(carrots); } } return renderer; }
Example #25
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 4 votes |
protected TiledMap loadMap (Element root, FileHandle tmxFile, AtlasResolver resolver, AtlasTiledMapLoaderParameters parameter) { TiledMap map = new TiledMap(); String mapOrientation = root.getAttribute("orientation", null); int mapWidth = root.getIntAttribute("width", 0); int mapHeight = root.getIntAttribute("height", 0); int tileWidth = root.getIntAttribute("tilewidth", 0); int tileHeight = root.getIntAttribute("tileheight", 0); String mapBackgroundColor = root.getAttribute("backgroundcolor", null); MapProperties mapProperties = map.getProperties(); if (mapOrientation != null) { mapProperties.put("orientation", mapOrientation); } mapProperties.put("width", mapWidth); mapProperties.put("height", mapHeight); mapProperties.put("tilewidth", tileWidth); mapProperties.put("tileheight", tileHeight); if (mapBackgroundColor != null) { mapProperties.put("backgroundcolor", mapBackgroundColor); } mapTileWidth = tileWidth; mapTileHeight = tileHeight; mapWidthInPixels = mapWidth * tileWidth; mapHeightInPixels = mapHeight * tileHeight; for (int i = 0, j = root.getChildCount(); i < j; i++) { Element element = root.getChild(i); String elementName = element.getName(); if (elementName.equals("properties")) { loadProperties(map.getProperties(), element); } else if (elementName.equals("tileset")) { loadTileset(map, element, tmxFile, resolver, parameter); } else if (elementName.equals("layer")) { loadTileLayer(map, element); } else if (elementName.equals("objectgroup")) { loadObjectGroup(map, element); } } return map; }
Example #26
Source File: LevelRenderer.java From ninja-rabbit with GNU General Public License v2.0 | 4 votes |
public TiledMap getTiledMap() { return renderer.getMap(); }
Example #27
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 4 votes |
public TiledMap load (String fileName) { return load(fileName, new AtlasTiledMapLoaderParameters()); }