Java 类com.badlogic.gdx.maps.tiled.TiledMapTile 实例源码

项目:odb-artax    文件:PowerSystem.java   
@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);
                }
            }
        }
    }
}
项目:jrpg-engine    文件:TileAnimation.java   
@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);
                    }
                }
            }
        }
    }
}
项目:jrpg-engine    文件:MapScanningDoorGenerator.java   
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;
}
项目:jrpg-engine    文件:MapScanningDoorGenerator.java   
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;
}
项目:Mario-Libgdx    文件:TmxMap.java   
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));
                }                   
            }
        }
    }
}
项目:Mario-Libgdx    文件:CastleLevelEndingSceneHandler.java   
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;       
}
项目:mario-game    文件:World.java   
/**
 * 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);
                }
            }
        }
    }
}
项目:mario-game    文件:World.java   
/**
 * 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);
                    }                       
                }
            }
        }
    }
}
项目:arcadelegends-gg    文件:Tile.java   
/**
 * 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;
}
项目:ExamensArbeteTD    文件:LevelManager.java   
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;
    }
项目:jrpg-engine    文件:TileAnimation.java   
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);
            }
        }
    }
}
项目:jrpg-engine    文件:Door.java   
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);
}
项目:jrpg-engine    文件:MapScanningDoorGenerator.java   
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])
                )
        );
    });
}
项目:jrpg-engine    文件:TiledUtil.java   
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);
    }
}
项目:fabulae    文件:Cell.java   
/**
 * 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;
}
项目:braingdx    文件:StatePopulator.java   
private void populateStateMap(int x, int y, State state, int layerIndex, TiledMapTileLayer layer,
      TiledMapConfig config) {
   Cell cell = layer.getCell(x, y);
   MapProperties layerProperties = layer.getProperties();
   boolean collisionLayer = Boolean
         .valueOf(layerProperties.get(config.get(Constants.COLLISION), "false", String.class));
   CellState cellState = state.getState(x, y, layerIndex);
   // Inherit the collision from the previous layer, if and only if
   // the current layer is non-collision by default
   if (layerIndex > 0 && !collisionLayer && state.getState(x, y, layerIndex - 1).isCollision()) {
      cellState.setCollision(true);
   } else if (cell != null) {
      TiledMapTile tile = cell.getTile();
      if (tile != null) {
         MapProperties properties = tile.getProperties();
         cellState.setProperties(properties);
         if (properties.containsKey(Constants.COLLISION)) {
            boolean collision = Boolean.valueOf(properties.get(Constants.COLLISION, String.class));
            cellState.setCollision(collision);
         } else {
            cellState.setCollision(DEFAULT_COLLISION);
         }
      } else {
         cellState.setCollision(DEFAULT_COLLISION);
      }
   } else {
      cellState.setCollision(DEFAULT_COLLISION);
   }
}
项目:braingdx    文件:MockTiledTileLayerBuilder.java   
MockTiledTileLayerBuilder addCell(int x, int y) {
   Cell cell = Mockito.mock(Cell.class);
   TiledMapTile tile = Mockito.mock(TiledMapTile.class);
   MapProperties layerProperties = new MapProperties();
   MapProperties properties = new MapProperties();
   Mockito.when(tile.getProperties()).thenReturn(properties);
   Mockito.when(cell.getTile()).thenReturn(tile);
   Mockito.when(layer.getCell(x, y)).thenReturn(cell);
   Mockito.when(layer.getProperties()).thenReturn(layerProperties);
   return this;
}
项目:RageGo    文件:GraphicStone.java   
/**
 * Generate the tiles for the given stone.
 * @return The tile which can be shown for this stone.
 */
private TiledMapTile generateTile() {
    if ((stone != null && stone.getPlayer() != null) && (goban != null && goban.getBoard() != null)) {
        if (goban.getBoard().getLetterForPlayer(stone.getPlayer()) == 'B') {
            return goban.getBlackStoneTile();
        } else return goban.getWhiteStoneTile();
    } else {
        return null;
    }
}
项目:swampmachine    文件:NavTmxMapLoader.java   
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);
}
项目:libgdxcn    文件:AnimatedTiledMapTile.java   
private TiledMapTile getCurrentFrame() {
    int currentTime = (int)(lastTiledMapRenderTime % loopDuration);

    for (int i = 0; i < animationIntervals.length; ++i){
        int animationInterval = animationIntervals[i];
        if (currentTime<=animationInterval) return frameTiles[i];
        currentTime -= animationInterval;
    }

    throw new GdxRuntimeException("Could not determine current animation frame in AnimatedTiledMapTile.  This should never happen.");
}
项目:libgdxcn    文件:HexagonalTiledMapTest.java   
@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);
}
项目:libgdx    文件:TiledMapManager.java   
/**
 * Devuelve el tile de una caja vac�a, para sustituir a la del interrogante
 * @param map El mapa actual
 * @return El tile
 */
public static TiledMapTile getEmptyBox(TiledMap map) {

    Iterator<TiledMapTile> tiles = map.getTileSets().getTileSet("tileset").iterator();
    while (tiles.hasNext()) {
        TiledMapTile tile = tiles.next();
        if ((tile.getProperties().containsKey("empty_box"))) {
            return tile;
        }
    }

    return null;
}
项目:mario-game    文件:World.java   
/**
 * Turn all bricks into actors.
 * @param layer
 */
private void generateBricks(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("actor")) {
                    String type = (String) oldTile.getProperties().get("actor");
                    StaticActor actor = null;
                    if(type.equals("Brick") || type.equals("Bonus")) {
                        //TODO add other colored bricks
                        String color = (String) oldTile.getProperties().get("color");
                        boolean destructable = false;
                        if(oldTile.getProperties().containsKey("destructable")) {

                            String destr = (String) oldTile.getProperties().get("destructable");
                            destructable = destr.equals("true") ? true : false;
                        }

                        actor = new Brick(this, x, y, color, type.equals("Bonus"), destructable);
                        itemsInBrick((Brick) actor, x, y);
                    }
                    layer.setCell(x, y, null);
                    stage.addActor(actor);
                }
            }
        }
    }
}
项目:Cypher-Sydekick    文件:MainScreen.java   
public void drawObjects(String layerID) {
    for (MapObject obj : map.getLayers().get(layerID).getObjects()) {
        MapProperties props = obj.getProperties();
        if (obj.isVisible()) {
            int gid = (Integer) props.get("gid");
            TiledMapTile tile = map.getTileSets().getTile(gid);
            renderer.getSpriteBatch().draw(tile.getTextureRegion(),
                    (Integer) props.get("x"), (Integer) props.get("y"));
        }
    }
}
项目:jrpg-engine    文件:Door.java   
private TiledMapTile getCurrentTile(final float percentOpen) {
    return closedToOpenFrames.get(getKeyFrameIndex(percentOpen));
}
项目:jrpg-engine    文件:MapScanningDoorGenerator.java   
private MapTile(final TileCoordinate coordinate, final String layerName, final TiledMapTile tile) {
    this.coordinate = coordinate;
    this.layerName = layerName;
    this.tile = tile;
}
项目:jrpg-engine    文件:MapScanningDoorGenerator.java   
public TiledMapTile getTile() {
    return tile;
}
项目:jrpg-engine    文件:TiledUtil.java   
public static TiledMapTile getTile(final TiledMap tiledMap, final String tilesetName, final int tileId) {
    final TiledMapTileSet tileset = tiledMap.getTileSets().getTileSet(tilesetName);
    return (tileset != null)
            ? tileset.getTile(tileset.getProperties().get(FISRTGID_PARAM, Integer.class) + tileId)
            : null;
}
项目:fabulae    文件:Cell.java   
/**
 * @return The tile currently assigned to this cell.
 */
public TiledMapTile getTile() {
    return super.getTile();
}
项目:Cypher-Sydekick    文件:Entity.java   
public static final TiledMapTile getTileRegion(int id) {
    return TILES.getTile(id);
}
项目:RageGo    文件:GraphicStone.java   
/**
 * Stone tile for this graphic stone
 * @return The tile generated by the constructor
 */
public TiledMapTile getStoneTile() {
    return stoneTile;
}
项目:RageGo    文件:Goban.java   
/**
 * Getter for {@link #blackStone}
 *
 * @return Tile used for black stone.
 */
public TiledMapTile getBlackStoneTile() {
    return blackStone;
}
项目:RageGo    文件:Goban.java   
/**
 * Getter for {@link #whiteStone}
 *
 * @return Tile used for white stones.
 */
public TiledMapTile getWhiteStoneTile() {
    return whiteStone;
}