List of usage examples for com.badlogic.gdx.maps.tiled TmxMapLoader load
public TiledMap load(String fileName)
From source file:com.agateau.pixelwheels.map.Track.java
License:Open Source License
public void init() { if (mMap != null) { return;// w w w . ja v a2s . c om } TmxMapLoader loader = new TmxMapLoader(); mMap = loader.load(Gdx.files.internal("maps/" + mId + ".tmx").path()); mMaterialForTileId = computeMaterialForTileId(); findSpecialTileIds(); findLayers(); readBorders(); mTileWidth = Constants.UNIT_FOR_PIXEL * mBackgroundLayers.get(0).getTileWidth(); mTileHeight = Constants.UNIT_FOR_PIXEL * mBackgroundLayers.get(0).getTileHeight(); mLapPositionTable = LapPositionTableIO.load(mMap); readWaypoints(); String bgColorText = mMap.getProperties().get("backgroundcolor", "#808080", String.class); bgColorText = bgColorText.substring(1); // Skip leading '#' mBackgroundColor = Color.valueOf(bgColorText); }
From source file:com.mygdx.game.Play.java
public Play(MyGdxGame dungeonCrawler) { initializePlayerValues();/*from w w w . j a v a 2 s .co m*/ initializeEnemyValues(); this.dungeonCrawler = dungeonCrawler; //hud = new HUD(dungeonCrawler.batch, enemy); enemyE = new Enemy(1, "enemy1", 50, 50, 1, 50, 1); enemies = new ArrayList<GameEnemy>(); TmxMapLoader loader = new TmxMapLoader(); map = loader.load("dungeon_Map1.tmx"); layer = map.getLayers().get(1); objects = layer.getObjects(); //sprite = new Sprite(new Texture("C:\\Users\\Thijs\\Desktop\\PTgame\\core\\assets\\sprite.jpg")); player = new Gameplayer(new Texture(Gdx.files.internal("knight_down.png")), new Texture(Gdx.files.internal("knight_up.png")), new Texture(Gdx.files.internal("knight_left.png")), new Texture(Gdx.files.internal("knight_right.png")), this); //enemy = new GameEnemy(new Texture(Gdx.files.internal("knight_down.png")), 100, 100); enemies.add(enemy); enemies.add(enemy2); enemies.add(enemy3); enemies.add(enemy4); enemies.add(enemy5); renderer = new OrthogonalTiledMapRenderer(map); camera = new OrthographicCamera(); hud = new HUD(dungeonCrawler.batch, hero, dungeon, enemyE); }
From source file:com.redtoorange.game.gameobject.GameMap.java
License:Open Source License
/** * Build a GameMap that will encapsulate a Tiled TMX Map. Scaling is handled automatically. Two Arrays will be * pulled from the TMX Map for object layers name: "walls", "playerspawn". * * @param parent The gameObject this is placed under, usually the scene root. * @param mapPath Rhe complete path from the Asset folder for the TMX file. * @param batch The SpriteBatch to embed into the MapRenderer. * @param camera The camera that is following the player, this is used for tile occlusion. * @param mapScale The amount to resize the entire map by. 1/16f if you want 16 map pixels to equal 1 game unit. */// w w w.j ava 2s . c o m public GameMap(GameObject parent, String mapPath, SpriteBatch batch, OrthographicCamera camera, float mapScale) { super(parent, new Vector2(0, 0)); this.mapScale = mapScale; TmxMapLoader mapLoader = new TmxMapLoader(new InternalFileHandleResolver()); map = mapLoader.load(mapPath); //Pull the properties from the TMX file. MapProperties properties = map.getProperties(); enemyCount = properties.get("enemy", Integer.class); healthCount = properties.get("health", Integer.class); ammoCount = properties.get("ammo", Integer.class); maxWidth = properties.get("width", Integer.class); maxHeight = properties.get("height", Integer.class); mapRenderer = new MapRenderComponent(map, mapScale, batch, camera); buildWalls(); buildPlayerSpawns(); }
From source file:com.trueMagic.maps.SectionLoader.java
public static void load() { TmxMapLoader tmxMapLoader = new TmxMapLoader(); TideMapLoader tideMapLoader = new TideMapLoader(); FileHandle mapFolder = Gdx.files.internal("Maps"); if (mapFolder.isDirectory()) { FileHandle[] mapFiles = mapFolder.list(); for (int i = 0; i < mapFiles.length; i++) { FileHandle mapFile = mapFiles[i]; if (mapFile.extension().equals("tmx")) { maps.put(mapFile.nameWithoutExtension(), new MapSection(tmxMapLoader.load(mapFile.path()))); } // else if(mapFile.extension().equals("tide")) { // maps.put(mapFile.nameWithoutExtension(), new MapSection(tideMapLoader.load(mapFile.path()))); //} }/*from w w w . j ava 2 s . com*/ } }
From source file:com.whynot.stClient.view.MainScreen.java
@Override public void show() { TmxMapLoader loader = new TmxMapLoader(); map = loader.load("maps/map_classic.tmx"); renderer = new OrthogonalTiledMapRenderer(map); camera = new OrthographicCamera(); }
From source file:org.example.game.map.GameMap.java
public void loadMap(TmxMapLoader tmxMapLoader, String mapFilename) { TiledMap tiledMap = tmxMapLoader.load(mapFilename); mapRenderer = new OrthogonalTiledMapRenderer(tiledMap, unitScale); this.map = tiledMap; }
From source file:se.angergard.game.system.MapControllerSystem.java
License:Apache License
@Override public void init() { maps = new TiledMap[Values.MAPS]; TmxMapLoader mapLoader = new TmxMapLoader(new InternalFileHandleResolver()); for (int i = 0; i < Values.MAPS; i++) { maps[i] = mapLoader.load("smallmaps/smallmap" + i + ".tmx"); }// ww w.j av a2 s. c o m solids = new boolean[Values.MAP_SIZE][Values.MAP_SIZE]; AStar.setSolids(solids); mapRenderer = new OrthogonalTiledMapRenderer(maps[3]); pointLights = new Array<Entity>(); enemies = new Array<Entity>(); runnablePool = new RunnablePool(); Objects.world.setContactListener(new ContactListener() { @Override public void beginContact(final Contact contact) { runnablePool.add(new Runnable() { @Override public void run() { if (Objects.world.isLocked()) { runnablePool.add(this); return; } if (contact == null) { return; } if (contact.getFixtureA() == null || contact.getFixtureB() == null) { return; } Entity e1 = (Entity) contact.getFixtureA().getUserData(); Entity e2 = (Entity) contact.getFixtureB().getUserData(); if (e1 == null || e2 == null) { return; } } }); } @Override public void endContact(Contact contact) { } @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } }); }
From source file:util.Utils.java
public static void setTilesFromTMX(BaseMap map, Maps id, String tmxFile, TileSet ts) { Tile[] tiles = new Tile[map.getWidth() * map.getHeight()]; FileHandleResolver resolver = new Constants.ClasspathResolver(); TmxMapLoader loader = new TmxMapLoader(resolver); TiledMap tm = loader.load("assets/tmx/" + tmxFile); TiledMapTileLayer ml = (TiledMapTileLayer) tm.getLayers().get(map.getId() + "-map"); if (ml != null) { FileHandle f = resolver.resolve("assets/graphics/latest-atlas.txt"); TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(f, f.parent(), false); int png_grid_width = 24; Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1]; for (TextureAtlas.TextureAtlasData.Region r : atlas.getRegions()) { int x = r.left / r.width; int y = r.top / r.height; int i = x + (y * png_grid_width) + 1; mapTileIds[i] = ts.getTileByName(r.name); if (mapTileIds[i] == null) { //System.out.printf("no tile found: %s %d\n",r.name,i); }// w w w .j a va2s. co m } for (int y = 0; y < map.getHeight(); y++) { for (int x = 0; x < map.getWidth(); x++) { StaticTiledMapTile tr = (StaticTiledMapTile) ml.getCell(x, map.getWidth() - 1 - y).getTile(); Tile tile = mapTileIds[tr.getId()]; if (tile == null) { System.out.printf("no tile found: %d %d %d\n", x, y, tr.getId()); } tiles[x + (y * map.getWidth())] = tile; } } } map.setTiles(tiles); MapLayer objectsLayer = tm.getLayers().get("portals"); if (objectsLayer != null) { Iterator<MapObject> iter = objectsLayer.getObjects().iterator(); while (iter.hasNext()) { MapObject obj = iter.next(); Portal p = map.getPortal(Maps.valueOf(obj.getName()).getId()); Iterator<String> keys = obj.getProperties().getKeys(); while (keys.hasNext()) { String key = keys.next(); String value = obj.getProperties().get(key).toString(); if (key.equals("x")) { p.setX(new Integer(value)); } else if (key.equals("y")) { p.setY(new Integer(value)); } } } } objectsLayer = tm.getLayers().get("moongates"); if (objectsLayer != null) { Iterator<MapObject> iter = objectsLayer.getObjects().iterator(); while (iter.hasNext()) { MapObject obj = iter.next(); Moongate m = map.getMoongate(obj.getName()); Iterator<String> keys = obj.getProperties().getKeys(); while (keys.hasNext()) { String key = keys.next(); String value = obj.getProperties().get(key).toString(); if (key.equals("x")) { m.setX(new Integer(value)); } else if (key.equals("y")) { m.setY(new Integer(value)); } } } } }