当前位置: 首页>>代码示例>>Java>>正文


Java TiledMap.getLayers方法代码示例

本文整理汇总了Java中com.badlogic.gdx.maps.tiled.TiledMap.getLayers方法的典型用法代码示例。如果您正苦于以下问题:Java TiledMap.getLayers方法的具体用法?Java TiledMap.getLayers怎么用?Java TiledMap.getLayers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.maps.tiled.TiledMap的用法示例。


在下文中一共展示了TiledMap.getLayers方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildMapLayers

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
private void buildMapLayers(final TiledMap map) {
    for (com.badlogic.gdx.maps.MapLayer mapLayer : map.getLayers()) {
        TiledMapTileLayer tiledMapLayer = (TiledMapTileLayer) mapLayer;

        if (tiledMapLayer.getProperties().containsKey(MAP_LAYER_PROP_MAP_LAYER)) {
            int mapLayerIndex = tiledMapLayer.getProperties().get(MAP_LAYER_PROP_MAP_LAYER, Integer.class);

            MapLayer gameMapLayer = mapLayers.computeIfAbsent(mapLayerIndex, i -> new MapLayer(i, mapRenderer));

            switch (tiledMapLayer.getProperties().get(MAP_LAYER_PROP_LAYER_TYPE, String.class)) {
                case MAP_LAYER_TYPE_BACKGRAOUND:
                    gameMapLayer.addBackgroundLayer(tiledMapLayer);
                    break;
                case MAP_LAYER_TYPE_FOREGRAOUND:
                    gameMapLayer.addForegroundLayer(tiledMapLayer);
                    break;
                case MAP_LAYER_TYPE_COLLISION:
                    gameMapLayer.setCollisionLayer(tiledMapLayer);
                    break;
                default:
            }
        }
    }
}
 
开发者ID:JayStGelais,项目名称:jrpg-engine,代码行数:25,代码来源:GameMap.java

示例2: getCellPropertyFromTopMostTile

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
public static <T> T getCellPropertyFromTopMostTile(final TiledMap tiledMap, final TileCoordinate coordinate,
                                                   final String propertyName, final Class<T> clazz) {
    T value = null;
    for (MapLayer mapLayer : tiledMap.getLayers()) {
        if (mapLayer instanceof TiledMapTileLayer
                && matchProperty(mapLayer, GameMap.MAP_LAYER_PROP_MAP_LAYER, coordinate.getMapLayer())) {
            TiledMapTileLayer tiledMapTileLayer = (TiledMapTileLayer) mapLayer;
            TiledMapTileLayer.Cell cell = tiledMapTileLayer.getCell(coordinate.getX(), coordinate.getY());
            if (cell != null) {
                final MapProperties cellProps = cell.getTile().getProperties();
                value = (cellProps.get(propertyName, clazz) != null) ? cellProps.get(propertyName, clazz) : value;
            }
        }
    }

    return value;
}
 
开发者ID:JayStGelais,项目名称:jrpg-engine,代码行数:18,代码来源:TiledUtil.java

示例3: load

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
public void load(TiledMap map) {
    MapProperties properties = map.getProperties();
    width = (Integer) properties.get(Tmx.WIDTH);
    height = (Integer) properties.get(Tmx.HEIGHT);
    objects = new MapObject[width][height];
    portals.clear();

    for (MapLayer layer : map.getLayers()) {
        for (MapObject object : layer.getObjects()) {
            if (object.getProperties().get("portal-id") != null) {
                portals.put((String) object.getProperties().get("portal-id"), object);
            }
            MapProperties objectProperties = object.getProperties();
            float x = (Float) objectProperties.get("x");
            float y = (Float) objectProperties.get("y");
            int indexX = (int) Math.floor(x / GameConfig.CELL_SCALE);
            int indexY = (int) Math.floor(y / GameConfig.CELL_SCALE);
            if (indexX >= 0 && indexY >= 0 && indexX < width && indexY < height) {
                objects[indexX][indexY] = object;
            }
        }
    }
}
 
开发者ID:bitbrain,项目名称:rbcgj-2016,代码行数:24,代码来源:MapActionHandler.java

示例4: populate

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
public void populate(TiledMap tiledMap, State state, Camera camera, MapLayerRendererFactory rendererFactory,
      TiledMapConfig config) {
   MapLayers mapLayers = tiledMap.getLayers();
   handleMapProperties(tiledMap.getProperties(), state, config);
   List<String> layerIds = new ArrayList<String>();
   int lastTileLayerIndex = 0;
   for (int i = 0; i < mapLayers.getCount(); ++i) {
      MapLayer mapLayer = mapLayers.get(i);
      if (mapLayer instanceof TiledMapTileLayer) {
         if (i > 0) {
            lastTileLayerIndex++;
         }
         String layerId = handleTiledMapTileLayer((TiledMapTileLayer) mapLayer, i, tiledMap, camera, rendererFactory,
               config);
         layerIds.add(layerId);
         populateStaticMapData(lastTileLayerIndex, (TiledMapTileLayer) mapLayer, state, config);
      } else {
         // Not a tiledlayer so consider it as an object layer
         handleObjectLayer(lastTileLayerIndex, mapLayer, state, config);
      }
   }
   state.setLayerIds(layerIds);
}
 
开发者ID:bitbrain,项目名称:braingdx,代码行数:24,代码来源:StatePopulator.java

示例5: genVoidMap

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
public static TiledMap genVoidMap(int w, int h) {
    ImpassableCells.clear();
    tileAtlas = ResKeeper.get(AtlasId.MAP_TILES);
    TiledMap map = new TiledMap();
    MapLayers layers = map.getLayers();
    TiledMapTileLayer layerBg = new TiledMapTileLayer(w, h, CELL_SIZE,
            CELL_SIZE);
    MapCell cell = getCell(TileCode.GRASS, true);
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            layerBg.setCell(i, j, cell);
        }
    }
    layers.add(layerBg);
    cells.clear();

    return map;
}
 
开发者ID:NaikSoftware,项目名称:SaveUA,代码行数:19,代码来源:MapUtils.java

示例6: generateInvertedMap

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
public static TiledMap generateInvertedMap(TiledMap map) {
	TiledMap invertedMap = new TiledMap();

	MapLayers invertedLayers = invertedMap.getLayers();

	for (int i = 0; i < map.getLayers().getCount(); i++) {
		TiledMapTileLayer origLayer = (TiledMapTileLayer) map.getLayers().get(i);

		TiledMapTileLayer tempLayer = invertLayer(origLayer);

		tempLayer.setOpacity(origLayer.getOpacity());
		tempLayer.setName(origLayer.getName());
		tempLayer.setVisible(origLayer.isVisible());
		copyLayerProperties(origLayer, tempLayer);

		invertedLayers.add(tempLayer);
	}

	return invertedMap;
}
 
开发者ID:UoLCompSoc,项目名称:mobius,代码行数:21,代码来源:LevelEntityFactory.java

示例7: getCollision

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
private boolean getCollision(TiledMap map, int x, int y) {
    boolean value = true;
    boolean npc = false;
    for (MapLayer layer : map.getLayers()) {
        for (MapObject o : layer.getObjects()) {
            MapProperties p = o.getProperties();
            if (p.get(Tmx.TYPE) != null && p.get(Tmx.TYPE).equals(Tmx.NPC)) {
                float oX = (Float)p.get(Tmx.X) + GameConfig.CELL_SCALE / 2f;
                float oY = (Float)p.get(Tmx.Y) + GameConfig.CELL_SCALE / 2f;
                // Normalize spawn position
                oX = (int)Math.floor(oX / GameConfig.CELL_SCALE);
                oY = (int)Math.floor(oY / GameConfig.CELL_SCALE);
                if (oX == x && oY == y) {
                    value = true;
                    npc = true;
                }
            }
        }
        if (layer instanceof TiledMapTileLayer) {
            TiledMapTileLayer tiledLayer = (TiledMapTileLayer) layer;
            TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y);
            if (cell != null && cell.getTile() != null) {
                MapProperties properties = cell.getTile().getProperties();
                boolean collision = Boolean.valueOf(properties.get(Tmx.COLLISION, "true", String.class));
                if (!collision && !npc) {
                    value = false;
                }
            }
        }
    }
    return value;
}
 
开发者ID:bitbrain,项目名称:rbcgj-2016,代码行数:33,代码来源:CollisionDetector.java

示例8: create

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
@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);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:38,代码来源:HexagonalTiledMapTest.java

示例9: create

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
@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);

}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:39,代码来源:TiledMapBench.java

示例10: Map

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
public Map(int levelNo, int tileSize){
	setPosition(0, 0);
	setOrigin(0, 0);
	TiledMap map = Asset.map(levelNo);
	this.tileSize = tileSize;
	mlayers  = map.getLayers();
	tileSets = map.getTileSets();
}
 
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:9,代码来源:Map.java

示例11: Box2DWorldCreator

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
/**
 * Sets up the collision boxes of the map objects
 */
public Box2DWorldCreator(PlayScreen screen) {
    this.playScreen = screen;

    TiledMap map = screen.getMap();
    MapLayers mapLayers = map.getLayers();

    // Loop through every layer in the map
    for (MapLayer mapLayer : mapLayers) {
        // Loop through every rectangular shape in this layer
        for (MapObject mapObject : mapLayer.getObjects().getByType(RectangleMapObject.class)) {

            // The rectangular collision box
            Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();

            // Create object depending on the type of the shape
            switch (mapLayer.getName()) {
                case "background":
                    // Only graphics
                    break;
                case "graphics":
                    // Only graphics
                    break;
                case "ground":
                    groundObjects.add(new Ground(screen, rectangle));
                    break;
                case "death":
                    deathTileObjects.add(new DeathTile(screen, rectangle));
                    break;
                case "weapon":
                    weaponPickupObjects.add(new WeaponPickup(screen, rectangle));
                    break;
                case "finish":
                    finishObjects.add(new Finish(screen, rectangle));
                    break;
                case "jumpable":
                    jumpableObjects.add(new Jumpable(screen, rectangle));
                    break;
                case "enemy_move_border":
                    enemyMoveBorderObjects.add(new EnemyMoveBorder(screen, rectangle));
                    break;
                case "enemies":
                    addEnemy(mapObject, ((RectangleMapObject) mapObject).getRectangle());
                    break;
                default:
                    break;
            }
        }
    }
}
 
开发者ID:johannesmols,项目名称:GangsterSquirrel,代码行数:53,代码来源:Box2DWorldCreator.java

示例12: generateCollisionMap

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
/**
 * <p>
 * Creates and returns a new {@link TerrainCollisionMap} from the given map.
 * If the map is not a valid Möbius map, the behaviour is undefined.
 * </p>
 * 
 * @param map
 *        The map from which to create a TerrainCollisionMap.
 * @return
 */
public static TerrainCollisionMap generateCollisionMap(TiledMap map, TiledMap mirrorMap) {
	TerrainCollisionMap retVal = null;

	MapLayers layers = map.getLayers();
	MapLayers mirrorLayers = mirrorMap.getLayers();

	TiledMapTileLayer egLayer = (TiledMapTileLayer) layers.get(0);
	HashMap<TiledMapTileLayer, PlatformManipulationHandler> platformLayers = new HashMap<TiledMapTileLayer, PlatformManipulationHandler>();

	ArrayList<Integer> collisionArray = null;

	for (int i = 0; i < layers.getCount(); i++) {
		TiledMapTileLayer origLayer = (TiledMapTileLayer) layers.get(i);
		TiledMapTileLayer mirrorLayer = (TiledMapTileLayer) mirrorLayers.get(i);

		if ((LevelEntityFactory.isSolidLayer(origLayer) && LevelEntityFactory.isSolidLayer(mirrorLayer))
				|| (LevelEntityFactory.isInteractableLayer(origLayer) && LevelEntityFactory
						.isInteractableLayer(mirrorLayer))) {
			if (collisionArray == null) {
				collisionArray = generateCollisionArray(origLayer, mirrorLayer);
			} else {
				if (origLayer.getOpacity() >= WorldConstants.GLOBAL_SOLID_OPACITY_THRESHOLD) {
					collisionArray = accumulateCollisionArray(collisionArray, origLayer, mirrorLayer);
				}
			}

			if (LevelEntityFactory.isInteractableLayer(origLayer)) {
				PlatformManipulationHandler handler = null;
				ArrayList<TerrainMapTileCoordinate> tileCoords = generatePlatformTileCoordinateArray(origLayer,
						mirrorLayer);

				InteractableLayerTypes layerType = LevelEntityFactory.getInteractableLayerType(origLayer);

				if (layerType.equals(InteractableLayerTypes.DX) || layerType.equals(InteractableLayerTypes.DY)) {
					handler = new MovingPlatformManipulationHandler(collisionArray, tileCoords,
							layerType.equals(InteractableLayerTypes.DX),
							layerType.equals(InteractableLayerTypes.DY));
				} else if (layerType.equals(InteractableLayerTypes.FADABLE)) {
					float opacity = origLayer.getOpacity();
					handler = new FadableLayerManipulationHandler(collisionArray, tileCoords,
							(opacity >= WorldConstants.GLOBAL_SOLID_OPACITY_THRESHOLD));
				}

				if (handler == null) {
					throw new GdxRuntimeException("Trying to create handler for invalid platform type.");
				} else {
					platformLayers.put(origLayer, handler);
					platformLayers.put(mirrorLayer, handler);
				}
			}
		}
	}

	retVal = new TerrainCollisionMap(egLayer, platformLayers, collisionArray);

	return retVal;
}
 
开发者ID:UoLCompSoc,项目名称:mobius,代码行数:68,代码来源:TerrainCollisionMap.java

示例13: create

import com.badlogic.gdx.maps.tiled.TiledMap; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:nfantone,项目名称:ninja-rabbit,代码行数:36,代码来源:LevelFactory.java


注:本文中的com.badlogic.gdx.maps.tiled.TiledMap.getLayers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。