use of com.badlogic.gdx.maps.tiled.TiledMap in project libgdx by libgdx.
the class TiledMapBench method create.
@Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, (w / h) * 320, 320);
camera.update();
cameraController = new OrthoCamController(camera);
Gdx.input.setInputProcessor(cameraController);
font = new BitmapFont();
batch = new SpriteBatch();
{
tiles = new Texture(Gdx.files.internal("data/maps/tiled/tiles.png"));
TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32);
map = new TiledMap();
MapLayers layers = map.getLayers();
for (int l = 0; l < 20; l++) {
TiledMapTileLayer layer = new TiledMapTileLayer(150, 100, 32, 32);
for (int x = 0; x < 150; x++) {
for (int y = 0; y < 100; y++) {
int ty = (int) (Math.random() * splitTiles.length);
int tx = (int) (Math.random() * splitTiles[ty].length);
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
layer.setCell(x, y, cell);
}
}
layers.add(layer);
}
}
renderer = new OrthogonalTiledMapRenderer(map);
}
use of com.badlogic.gdx.maps.tiled.TiledMap in project libgdx by libgdx.
the class HexagonalTiledMapTest method create.
@Override
public void create() {
super.create();
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, (w / h) * 480, 480);
camera.update();
cameraController = new OrthoCamController(camera);
Gdx.input.setInputProcessor(cameraController);
hexture = new Texture(Gdx.files.internal("data/maps/tiled/hex/hexes.png"));
TextureRegion[][] hexes = TextureRegion.split(hexture, 112, 97);
map = new TiledMap();
MapLayers layers = map.getLayers();
TiledMapTile[] tiles = new TiledMapTile[3];
tiles[0] = new StaticTiledMapTile(new TextureRegion(hexes[0][0]));
tiles[1] = new StaticTiledMapTile(new TextureRegion(hexes[0][1]));
tiles[2] = new StaticTiledMapTile(new TextureRegion(hexes[1][0]));
for (int l = 0; l < 1; l++) {
TiledMapTileLayer layer = new TiledMapTileLayer(45, 30, 112, 97);
for (int y = 0; y < 30; y++) {
for (int x = 0; x < 45; x++) {
int id = (int) (Math.random() * 3);
Cell cell = new Cell();
cell.setTile(tiles[id]);
layer.setCell(x, y, cell);
}
}
layers.add(layer);
}
renderer = new HexagonalTiledMapRenderer(map);
}
use of com.badlogic.gdx.maps.tiled.TiledMap in project AmazingMaze by TheVirtualMachine.
the class MapFactory method generateMap.
/**
* Return a map generated with the {@link MapFactory}'s parameters.
*
* @return a tiled map.
*/
public TiledMap generateMap() {
TiledMap map = new TiledMap();
map.getTileSets().addTileSet(assets.tiles);
TiledMapTileLayer backgroundLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
backgroundLayer.setName(BACKGROUND_LAYER);
for (int c = 0; c < backgroundLayer.getWidth(); c++) {
for (int r = 0; r < backgroundLayer.getHeight(); r++) {
Cell cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BACKGROUND)));
backgroundLayer.setCell(c, r, cell);
}
}
map.getLayers().add(backgroundLayer);
final int gateSpace = 2;
final int extraRoom = 3;
List<Integer> splits = generateWireLocations();
TiledMapTileLayer objectLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
objectLayer.setName(OBJECT_LAYER);
TiledMapTileLayer wireLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
wireLayer.setName(WIRE_LAYER);
for (int col : splits) {
// Place the middle barriers and the unknown wires.
boolean upperOutput = random.nextBoolean();
Circuit upperGate = new Circuit(upperOutput, random);
Circuit lowerGate = new Circuit(!upperOutput, random);
Point highLocation = new Point(col, height - gateSpace);
Point lowLocation = new Point(col, gateSpace - 1);
if (Circuit.evaluateGate(upperGate.getGate(), upperGate.isInputA(), upperGate.isInputB())) {
gateOn.add(upperGate);
} else {
gateOn.add(lowerGate);
}
placeUpperCircuit(objectLayer, upperGate, highLocation);
placeLowerCircuit(objectLayer, lowerGate, lowLocation);
int barrierLoc = randomInt(gateSpace + extraRoom, height - (gateSpace + extraRoom));
Cell cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BARRIER)));
objectLayer.setCell(col, barrierLoc, cell);
for (int r = barrierLoc - 1; r >= gateSpace; r--) {
// Place the lower wires.
WireCell wire = new WireCell(!upperOutput);
wire.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.UNKNOWN)));
wireLayer.setCell(col, r, wire);
}
for (int r = barrierLoc + 1; r < height - gateSpace; r++) {
// Place the upper wires.
WireCell wire = new WireCell(upperOutput);
wire.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.UNKNOWN)));
wireLayer.setCell(col, r, wire);
}
}
for (int c = 0; c < width; c++) {
if (!splits.contains(c)) {
Cell cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BARRIER)));
objectLayer.setCell(c, gateSpace, cell);
cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BARRIER)));
objectLayer.setCell(c, height - gateSpace - 1, cell);
}
}
map.getLayers().add(objectLayer);
map.getLayers().add(wireLayer);
TiledMapTileLayer powerUpLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
powerUpLayer.setName(ITEM_LAYER);
for (int c = 1; c < width; c++) {
if (!splits.contains(c)) {
if (random.nextDouble() <= 0.25) {
placeFish(powerUpLayer, c, gateSpace);
c++;
} else if (random.nextDouble() <= 0.1) {
placeCheese(powerUpLayer, c, gateSpace);
c++;
}
}
}
map.getLayers().add(powerUpLayer);
return map;
}
use of com.badlogic.gdx.maps.tiled.TiledMap in project Entitas-Java by Rubentxu.
the class TiledRendererSystem method initialize.
@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);
}
use of com.badlogic.gdx.maps.tiled.TiledMap in project Entitas-Java by Rubentxu.
the class TiledRendererSystem method execute.
@Override
protected void execute(List<SceneEntity> gameEntities) {
Tiled tiled = context.getTiled();
TiledMap tiledMap = assetsManager.getMap(tiled.tileMapName);
tiledRenderer.setMap(tiledMap);
tiledRenderer.setView((OrthographicCamera) cam);
}
Aggregations