本文整理汇总了Java中com.badlogic.gdx.maps.tiled.TiledMapTile类的典型用法代码示例。如果您正苦于以下问题:Java TiledMapTile类的具体用法?Java TiledMapTile怎么用?Java TiledMapTile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TiledMapTile类属于com.badlogic.gdx.maps.tiled包,在下文中一共展示了TiledMapTile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
@Override
protected void initialize() {
super.initialize();
cableMask = mapSystem.getMask("cable-type");
for (TiledMapTileSet tileSet : mapSystem.map.getTileSets()) {
for (TiledMapTile tile : tileSet) {
MapProperties properties = tile.getProperties();
if (properties.containsKey("cable-type")) {
if ((Boolean) properties.get("cable-state")) {
tilesOn.put((Integer) properties.get("cable-type"), tile);
} else {
tilesOff.put((Integer) properties.get("cable-type"), tile);
}
}
}
}
}
示例2: update
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
@Override
public void update(final long elapsedTime) {
timeInAnimation = (timeInAnimation + elapsedTime) % getTotalAnimationTimeMs();
final int frameIndex = (int) (timeInAnimation / timePerFrameMs);
TiledMapTile currentTile = tileFrames.get(indexOrder[frameIndex]);
for (MapLayer layer : tiledMap.getLayers()) {
TiledMapTileLayer tiledMapLayer = (TiledMapTileLayer) layer;
for (int x = 0; x < tiledMapLayer.getWidth(); x++) {
for (int y = 0; y < tiledMapLayer.getHeight(); y++) {
final TiledMapTileLayer.Cell cell = tiledMapLayer.getCell(x, y);
if (cell != null) {
TiledMapTile tile = cell.getTile();
final MapProperties tileProperties = tile.getProperties();
if (tileProperties.containsKey(JRPG_TILE_ANIMATION_ID)
&& tileProperties.get(JRPG_TILE_ANIMATION_ID).equals(id)) {
cell.setTile(currentTile);
}
}
}
}
}
}
示例3: buildDoorAnimations
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
private Map<String, TiledMapTile[]> buildDoorAnimations(final GameMap map, final List<String> animationIds) {
final Map<String, Map<Integer, TiledMapTile>> animationTiles = new HashMap<>();
map.getTiledMap().getTileSets().forEach(tileSet -> {
tileSet.forEach((TiledMapTile tile) -> {
final MapProperties tileProperties = tile.getProperties();
final String animationId = tileProperties.get(TileAnimation.JRPG_TILE_ANIMATION_ID, String.class);
if (animationIds.contains(animationId)) {
int animationIndex = tileProperties.get(TileAnimation.JRPG_TILE_ANIMATION_INDEX, Integer.class);
animationTiles.computeIfAbsent(animationId, key -> new TreeMap<>()).put(animationIndex, tile);
}
});
});
final Map<String, TiledMapTile[]> animations = new HashMap<>();
animationTiles.keySet().forEach(animationId -> {
animations.put(animationId, animationTiles.get(animationId).values().toArray(new TiledMapTile[0]));
});
return animations;
}
示例4: getDoorTiles
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
private List<MapTile> getDoorTiles(final TiledMapTileLayer layer) {
final List<MapTile> mapTiles = new LinkedList<>();
final int layerIndex = layer.getProperties().get(GameMap.MAP_LAYER_PROP_MAP_LAYER, 0, Integer.class);
for (int x = 0; x < layer.getWidth(); x++) {
for (int y = 0; y < layer.getHeight(); y++) {
final TiledMapTileLayer.Cell cell = layer.getCell(x, y);
TiledMapTile tile = (cell != null) ? cell.getTile() : null;
if (tile != null && tile.getProperties().get(JRPG_TILE_IS_DOOR, false, Boolean.class)) {
mapTiles.add(new MapTile(
new TileCoordinate(x, y, layerIndex),
layer.getName(),
tile
));
}
}
}
return mapTiles;
}
示例5: initBlocks
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
private void initBlocks(WorldTypeEnum background) {
blocks = new ArrayList<AbstractBlock>();
wallBlocks = new ArrayList<WallBlock>();
for (int i = 0; i < tileLayer.getWidth(); i++) {
for (int j = 0; j < tileLayer.getHeight(); j++) {
Cell cell = tileLayer.getCell(i, j);
if (cell != null) {
TiledMapTile tile = cell.getTile();
int id = tile.getId();
BlockTypeEnum blockTypeEnum = TileIdConstants.getSpecialBlockType(id);
if (blockTypeEnum==BlockTypeEnum.MYSTERY_BLOCK) {
blocks.add(new MysteryBlock(i, j, id, background));
} else if (blockTypeEnum==BlockTypeEnum.WALL_BLOCK) {
wallBlocks.add(new WallBlock(i, j, id, background));
} else if (blockTypeEnum==BlockTypeEnum.MYSTERY_BLOCK_INVISIBLE) {
blocks.add(new InvisibleMysteryBlock(i, j, id, background));
}
}
}
}
}
示例6: CastleLevelEndingSceneHandler
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
public CastleLevelEndingSceneHandler(Mario mario, TmxMap tileMap, GameCamera camera,
Array<IScrollingBackground> scrollingBbackgrounds, BitmapFont font, SpriteBatch spriteBatch,
OrthogonalTiledMapRenderer renderer, Stage stage, Batch batch) {
super(mario, tileMap, camera, scrollingBbackgrounds, font, spriteBatch, renderer, stage, batch);
for (int i = 0; i < tileMap.getTileLayer().getWidth(); i++) {
for (int j = 0; j < tileMap.getTileLayer().getHeight(); j++) {
Cell cell = tileMap.getTileLayer().getCell(i, j);
if (cell != null) {
TiledMapTile tile = cell.getTile();
int id = tile.getId();
if (id==118) {
tileToRemove.add(new Vector2(i,j));
}
}
}
}
for (AbstractEnemy enemy : tileMap.getEnemies()) {
if (enemy.getEnemyType()==EnemyTypeEnum.BOWSER) {
if (!enemy.isKilled()) {
bowser = enemy;
}
}
}
updateEnemies = true;
}
示例7: animateTiles
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
/**
* Make the tiles containing 'animation' key animated.
* @param layer
*/
private void animateTiles(TiledMapTileLayer layer) {
for (int x = 1; x < layer.getWidth(); x++) {
for (int y = 1; y < layer.getHeight(); y++) {
Cell cell = layer.getCell(x, y);
if(cell != null) {
TiledMapTile oldTile = cell.getTile();
if(oldTile.getProperties().containsKey("animation")) {
String animation = (String) oldTile.getProperties().get("animation");
float speed = 0.15f;
if(oldTile.getProperties().containsKey("speed")) {
speed = Float.parseFloat((String) oldTile.getProperties().get("speed"));
}
AnimatedTiledMapTile newTile = new AnimatedTiledMapTile(speed,
Tiles.getAnimatedTile(animation));
newTile.getProperties().putAll(oldTile.getProperties());
cell.setTile(newTile);
}
}
}
}
}
示例8: initTileset
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
/**
* Tiles that have a 'texture' property will be using an optimized tileset. This is to avoid screen tearing.
* @param layer
*/
private void initTileset(TiledMapTileLayer layer) {
ArrayMap<String, TextureRegion> textureArr = new ArrayMap<String, TextureRegion>();
for(int x = 0; x < layer.getWidth(); x++) {
for(int y = 0; y < layer.getHeight(); y++) {
Cell cell = layer.getCell(x, y);
if(cell != null) {
TiledMapTile oldTile = cell.getTile();
if(oldTile.getProperties().containsKey("texture")) {
//D.o("Initializing textures");
String texture = (String) oldTile.getProperties().get("texture");
if(textureArr.containsKey(texture)) {
oldTile.getTextureRegion().setRegion(textureArr.get(texture));
}
else {
TextureRegion t = Tiles.getTile(texture);
textureArr.put(texture, t);
oldTile.getTextureRegion().setRegion(t);
}
}
}
}
}
}
示例9: fromTileMapTile
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
/**
* Creates a {@link Tile} from a {@link TiledMapTile}.
*
* @param tiledMapTile the tiledMapTile from which to read from
* @param x coordinate
* @param y coordinate
* @return the created Tile
*/
public static Tile fromTileMapTile(TiledMapTile tiledMapTile, int x, int y) {
MapProperties mapProperties = tiledMapTile.getProperties();
Tile tile = new Tile(x, y);
if (mapProperties.get("untraversable") != null)
tile.setTraversable(mapProperties.get("untraversable", Boolean.class));
return tile;
}
示例10: checkIfWall
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
private static boolean checkIfWall(int x, int y) {
TiledMapTile tile = null;
try {
tile = collisionLayer.getCell(x, y).getTile();
} catch (NullPointerException e) {
// System.out.println(e);
}
if (tile != null) {
boolean iswall = tile.getProperties().get("Wall", Boolean.class);
if (iswall)
return true;
}
return false;
}
示例11: findTileFrames
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
private void findTileFrames() {
for (TiledMapTileSet tileSet : tiledMap.getTileSets()) {
for (TiledMapTile tile : tileSet) {
final MapProperties tileProperties = tile.getProperties();
if (tileProperties.containsKey(JRPG_TILE_ANIMATION_ID)
&& tileProperties.get(JRPG_TILE_ANIMATION_ID).equals(id)) {
tileFrames.put(tileProperties.get(JRPG_TILE_ANIMATION_INDEX, Integer.class), tile);
}
}
}
}
示例12: DoorTile
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
public DoorTile(final GameMap map, final String layerName, final TileCoordinate location,
final TiledMapTile... frames) {
this.map = map;
this.layerName = layerName;
this.location = location;
closedToOpenFrames = Arrays.asList(frames);
}
示例13: createDoors
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
public void createDoors(final GameMap map) {
final Set<MapTile> doorTiles = findDoorTiles(map);
final Map<String, TiledMapTile[]> animations = buildDoorAnimations(map, getDistinctAnimationIds(doorTiles));
final Set<Set<MapTile>> tileClusters = new HashSet<>();
doorTiles.forEach(doorTile -> {
Set<MapTile> cluster = new HashSet<>();
cluster.add(doorTile);
for (MapTile mapTile : doorTiles) {
if (!doorTile.equals(mapTile) && isAdjacent(doorTile, mapTile)) {
cluster.add(mapTile);
}
}
tileClusters.add(cluster);
});
tileClusters.forEach(cluster -> {
map.addDoor(
new Door(
getNextDoorId(map),
openAction,
lockCheck,
animationTimeMs,
cluster.stream().map(mapTile -> new Door.DoorTile(
map,
mapTile.getLayerName(),
mapTile.getCoordinate(),
animations.get(
mapTile
.getTile()
.getProperties()
.get(TileAnimation.JRPG_TILE_ANIMATION_ID, String.class)
)
)).collect(Collectors.toList()).toArray(new Door.DoorTile[0])
)
);
});
}
示例14: updateTile
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
public static void updateTile(final TiledMap tiledMap, final TileCoordinate location,
final String layerName, final TiledMapTile tile) {
final TiledMapTileLayer mapLayer = (TiledMapTileLayer) tiledMap.getLayers().get(layerName);
if (mapLayer != null && matchProperty(mapLayer, GameMap.MAP_LAYER_PROP_MAP_LAYER, location.getMapLayer())) {
mapLayer.getCell(location.getX(), location.getY()).setTile(tile);
}
}
示例15: setTile
import com.badlogic.gdx.maps.tiled.TiledMapTile; //导入依赖的package包/类
/**
* Sets the tile to be used for this cell.
*
* @param tile
*/
public Cell setTile(TiledMapTile tile) {
super.setTile(tile);
animated = false;
if (tile instanceof AnimatedTile) {
animated = true;
stateTime = 0;
randomDelay = 0;
if (((AnimatedTile) tile).hasRandomDelay()) {
randomDelay = MathUtils.random(((AnimatedTile) tile).getAnimationDuration());
stateTime = randomDelay;
}
}
return this;
}