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

项目:fabulae    文件:TiledMapLoader.java   
protected Cell createTileLayerCell (boolean flipHorizontally, boolean flipVertically, boolean flipDiagonally) {
    Cell cell = new mg.fishchicken.maps.Cell();
    if (flipDiagonally) {
        if (flipHorizontally && flipVertically) {
            cell.setFlipHorizontally(true);
            cell.setRotation(Cell.ROTATE_270);
        } else if (flipHorizontally) {
            cell.setRotation(Cell.ROTATE_270);
        } else if (flipVertically) {
            cell.setRotation(Cell.ROTATE_90);
        } else {
            cell.setFlipVertically(true);
            cell.setRotation(Cell.ROTATE_270);
        }
    } else {
        cell.setFlipHorizontally(flipHorizontally);
        cell.setFlipVertically(flipVertically);
    }
    return cell;
}
项目:DropTheCube-LD32    文件:MapControllerSystem.java   
private void initSolidTiles(TiledMap map){
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("CollisionTiles");

    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){
                solids[x][y] = false;
                continue;
            }
            if(cell.getTile() == null){
                solids[x][y] = false;
                continue;
            }
            else{
                solids[x][y] = true;
            }
        }
    }
}
项目: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;       
}
项目:TTmath    文件:EntityManager.java   
public Vector2 findStartPosition(){

        Vector2 start = null;
        Cell temp;
        //tile width and height = 32, so multiple width and height to get the area
        //add stepx and stepy by 32 to move between each tile
        for(int y = 0; y < tiles.getHeight(); y++){
            for(int x = 0; x < tiles.getWidth(); x++){
                temp = tiles.getCell(x, y);
                if( temp != null && temp.getTile().getProperties().containsKey("start")){
                    start = new Vector2((x * tiles.getTileWidth()), (y * tiles.getTileHeight()));
                    break;
                }
            }
            if(start != null){
                break;
            }
        }
        if(start == null){
            System.out.println("could not find start position");
        }
        return start;
    }
项目:TTmath    文件:Player.java   
private String retrieveItem() {
    Cell cell = collisionLayer.getCell((int)(this.pos.x/tileWidth), (int)(this.pos.y/tileHeight));
    if(cell != null){
        String item = null;
        Iterator<String> obj = cell.getTile().getProperties().getKeys();
        while(obj.hasNext()){
            item = obj.next();
        }
        System.out.println(item);
        collisionLayer.setCell((int)(this.pos.x/tileWidth), (int)(this.pos.y/tileHeight), null);
        return item;
    }
    else {
        System.out.println("current tile has no items on it");
        return "null";
    }
}
项目:libgdxcn    文件:BaseTmxMapLoader.java   
protected Cell createTileLayerCell (boolean flipHorizontally, boolean flipVertically, boolean flipDiagonally) {
    Cell cell = new Cell();
    if (flipDiagonally) {
        if (flipHorizontally && flipVertically) {
            cell.setFlipHorizontally(true);
            cell.setRotation(Cell.ROTATE_270);
        } else if (flipHorizontally) {
            cell.setRotation(Cell.ROTATE_270);
        } else if (flipVertically) {
            cell.setRotation(Cell.ROTATE_90);
        } else {
            cell.setFlipVertically(true);
            cell.setRotation(Cell.ROTATE_270);
        }
    } else {
        cell.setFlipHorizontally(flipHorizontally);
        cell.setFlipVertically(flipVertically);
    }
    return cell;
}
项目:SaveUA    文件:SelectPanelCell.java   
/**
   * Конструктор для создания тайлов на панель в редакторе
   *
   * @param cell
   * @param size
   */
  public SelectPanelCell(Cell cell) {
      super();
      this.cell = cell;
      TextureRegionDrawable d = new TextureRegionDrawable(cell.getTile().getTextureRegion());
      setDrawable(d);
float size = d.getMinHeight();
      setOrigin(size / 2, size / 2);

      switch (cell.getRotation()) {
          case Cell.ROTATE_90:
              setRotation(90);
              break;
          case Cell.ROTATE_180:
              setRotation(180);
              break;
          case Cell.ROTATE_270:
              setRotation(270);
              break;
          default:
              break;
      }
  }
项目:Shadow-of-Goritur    文件:MapLoader.java   
public static void loadMap(String fileName) {
    TiledMap map = new TmxMapLoader().load(fileName);
    for (int i = 0; i < map.getLayers().getCount(); i++) {
        TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers()
                .get(i);
        for (int x = 0; x < layer.getWidth(); x++) {
            for (int y = 0; y < layer.getHeight(); y++) {
                Cell cell = layer.getCell(x, layer.getHeight() - 1 - y);
                if (cell == null) {
                    continue;
                }
                Entity e = EntityManager.createTile((String) cell.getTile()
                        .getProperties().get("name"), x * 16, y * 16);
                EntityManager.setEntityLayer(e, Name.LAYER_FLOOR);
            }
        }
    }
}
项目:libgdx    文件:SpriteManager.java   
/**
 * Obtiene la lista de celdas de interés en las que está situado el jugador
 * Ahora mismo sólo comprueba las celdas de las casas
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @param tiles
 */
private void getTilesPosition(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {

    tiles.clear();

    for (int y = startY; y <= endY; y++) {
        for (int x = startX; x <= endX; x++) {
            int xCell = (int) (x / collisionLayer.getTileWidth());
            int yCell = (int) (y / collisionLayer.getTileHeight());
            Cell cell = collisionLayer.getCell(xCell, yCell);

            // Si es un bloque se añade para comprobar colisiones
            if ((cell != null) && (cell.getTile().getProperties().containsKey("house"))) {
                Rectangle rect = rectPool.obtain();
                rect.set((int) (Math.ceil(x / 16f) * 16), (int) (Math.ceil(y / 16f) * 16), 0, 0);
                tiles.add(rect);
            }
        }
    }
}
项目:libgdx    文件:Item.java   
/**
 * Obtiene una lista de celdas con las que colisiona el item
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @return
 */
private void getTilesPosition(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {

    tiles.clear();

    for (int y = startY; y <= endY; y++) {
        for (int x = startX; x <= endX; x++) {
            int xCell = (int) (x / TiledMapManager.collisionLayer.getTileWidth());
            int yCell = (int) (y / TiledMapManager.collisionLayer.getTileHeight());
            Cell cell = TiledMapManager.collisionLayer.getCell(xCell, yCell);

            // Si es un bloque se a�ade para comprobar colisiones
            if ((cell != null) && (cell.getTile().getProperties().containsKey(TiledMapManager.BLOCKED))) {
                Rectangle rect = rectPool.obtain();

                rect.set((int) (Math.ceil(x / 16f) * 16), (int) (Math.ceil(y / 16f) * 16), 0, 0);
                tiles.add(rect);
            }
        }
    }
}
项目:libgdx    文件:Enemy.java   
/**
 * Obtiene una lista de celdas con las que colisiona el enemigo
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @return
 */
private void getTilesPosition(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {

    tiles.clear();

    for (int y = startY; y <= endY; y++) {
        for (int x = startX; x <= endX; x++) {
            int xCell = (int) (x / TiledMapManager.collisionLayer.getTileWidth());
            int yCell = (int) (y / TiledMapManager.collisionLayer.getTileHeight());
            Cell cell = TiledMapManager.collisionLayer.getCell(xCell, yCell);

            // Si es un bloque se a�ade para comprobar colisiones
            if ((cell != null) && (cell.getTile().getProperties().containsKey(TiledMapManager.BLOCKED))) {
                Rectangle rect = rectPool.obtain();

                rect.set((int) (Math.ceil(x / 16f) * 16), (int) (Math.ceil(y / 16f) * 16), 0, 0);
                tiles.add(rect);
            }
        }
    }
}
项目:GdxStudio    文件:Map.java   
public void loadLayer(int layerNo){
    Scene.log("Tiles Layer no: "+layerNo);
    TiledMapTileLayer layer = (TiledMapTileLayer)mlayers.get(layerNo);
    NoOfColumns = layer.getWidth();
    Scene.log("MapColumns: "+NoOfColumns);
    NoOfRows = layer.getHeight();
    Scene.log("MapRows: "+NoOfRows);
    tiles .add(new MapActor[NoOfRows][NoOfColumns]);
    for(int i=0; i<NoOfRows; i++)
        for(int j=0; j<NoOfColumns; j++){
            Cell c = layer.getCell(j, i);
            if(c != null){
                tiles.get(layerNo)[i][j] = new MapActor(c.getTile().getTextureRegion(),
                        i, j, c.getTile().getId(), tileSize);
                addActor(tiles.get(layerNo)[i][j]);
            }
            else{
                tiles.get(layerNo)[i][j] = new MapActor((TextureRegion)null,i, j, 0, tileSize);
                addActor(tiles.get(layerNo)[i][j]);
            }
    }
    mapWidth = tileSize * NoOfColumns;
    mapHeight = tileSize * NoOfRows;
    //Stage.mapOffsetX = mapWidth - Stage.camOffsetX;
    //Stage.mapOffsetY = mapHeight - Stage.camOffsetYTop;
}
项目:Missing_Words    文件:World.java   
private void generateHoles() {
    Random r = new Random();
    int counter = 0;

    for (int x = 0; x < pathLayer.getWidth(); ++x)
        for (int y = 0; y < pathLayer.getHeight(); ++y) {
            Cell cell = pathLayer.getCell(x, y);
            if (cell == null)
                continue;       
            else if (cell.getTile().getProperties().containsKey("path")) {
                int num = r.nextInt(10 - 1 + 1) + 1;
                if (num >= 9) {
                    ++counter;
                    if (counter <= 4)
                        cell.setTile(holeTile);
                }
                else
                    counter = 0;
            }
        }
}
项目: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);
                    }                       
                }
            }
        }
    }
}
项目:mario-game    文件:World.java   
public Array<Rectangle> getTiles(int startX, int startY, int endX, int endY)
{
    Array<Rectangle> tiles = new Array<Rectangle>();
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("walls");
    rectPool.freeAll(tiles);
    tiles.clear();
    for (int y = startY; y <= endY; y++)
    {
        for (int x = startX; x <= endX; x++)
        {
            Cell cell = layer.getCell(x, y);
            if (cell != null)
            {
                Rectangle rect = rectPool.obtain();
                rect.set(x, y, 1, 1);
                tiles.add(rect);
            }
        }
    }
    return tiles;
}
项目:KyperBox    文件:TilemapLayerObject.java   
public void init(float x,float y,float tilewidth,float tileheight,Cell cell) {
    this.cell = cell;
    this.x = x;
    this.y = y;
    this.width = tilewidth;
    this.height = tileheight;
}
项目:Space-Bombs    文件:Bomb.java   
/**
 * Deltes block on given cell position. Spawns also a coin randomly on destroyed blocks.
 * If it is undestructable nothing happens and false gets returned.
 * @param x: Cell position on x axis
 * @param y: Cell position on y axis
 * @return boolean
 */ 
protected boolean deleteBlock(MapCellCoordinates localCellPos)
{
    Cell currentCell = blockLayer.getCell(localCellPos.getX() , localCellPos.getY());

    if(currentCell != null)
    {
        //If block is undestructable
        if(currentCell.getTile().getProperties().containsKey("undestructable"))
        {
            return false;

        }else
        {
            //Delete block with empty texture
            Cell cell = new Cell();
            cell.setTile(new StaticTiledMapTile(emptyBlock));
            map.getBlockLayer().setCell(localCellPos.getX(), localCellPos.getY(), cell);


            /**---------------------RANDOM COIN---------------------**/
            //Check for a bug and if main player placed that bomb
            if(currentCell.getTile().getId() != cell.getTile().getId() && playerId == Constants.PLAYERID)
            {
                dropFromBlock(localCellPos);
            }
        }
    }

    // If there is no block 
    return true;
}
项目:fabulae    文件:GameMapLoader.java   
private void calculateMoveCosts() {
    Cell cell;
    int width = map.getProperties().get("width", Integer.class);
    int height = map.getProperties().get("height", Integer.class);
    gameMap.moveCosts = new float[width * height];

    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            float moveCost = -1;
            for (MapLayer layer : gameMap.getTiledMap().getLayers()) {
                if (layer instanceof TiledMapTileLayer) {
                    cell = ((TiledMapTileLayer) layer).getCell(x, y);
                    if (cell != null) {
                        MapProperties tileProperties = cell.getTile().getProperties();
                        Object cost = tileProperties.get(GameMapLoader.PROPERTY_MOVE_COST);
                        if (cost != null) {
                            float newCost = Float.valueOf((String) cost);
                            if (newCost > moveCost) {
                                moveCost = newCost;
                            }
                        }
                    }
                }
            }
            if (moveCost < 0) {
                moveCost = 1;
            }
            gameMap.moveCosts[x + y * width] = moveCost;
        }
    }
}
项目:braingdx    文件:StatePopulator.java   
private void populateHeightMap(int x, int y, State state, int layerIndex, TiledMapTileLayer layer) {
   Cell cell = layer.getCell(x, y);
   if (cell != null) {
      Integer[][] heightMap = state.getHeightMap();
      heightMap[x][y] = IndexCalculator.calculateZIndex(state.getMapIndexHeight(), y, layerIndex);
   }
}
项目: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;
}
项目:braingdx    文件:MockTiledMapBuilder.java   
public MockTiledMapBuilder addLayer() {
   TiledMapTileLayer layer = mock(TiledMapTileLayer.class);
   Cell cell = mock(Cell.class);
   MapProperties properties = new MapProperties();
   when(layer.getCell(anyInt(), anyInt())).thenReturn(cell);
   when(layer.getTileWidth()).thenReturn(size);
   when(layer.getTileHeight()).thenReturn(size);
   Mockito.when(layer.getProperties()).thenReturn(properties);
   layers.add(layer);
   return this;
}
项目:Mario-Libgdx    文件:TmxMap.java   
public boolean isCollisioningTileAt(int x, int y) {
    Cell cell = tileLayer.getCell(x, y);
    if (cell != null) {
        return cell.getTile().getId() <= 128 && !TileIdConstants.isInvisibleBlock(cell.getTile().getId());
    }       
    return false;
}
项目:Mario-Libgdx    文件:TmxMap.java   
public boolean isCollisioningInvisibleTileAt(int x, int y) {
    Cell cell = tileLayer.getCell(x, y);
    if (cell != null) {
        return TileIdConstants.isInvisibleBlock(cell.getTile().getId());
    }       
    return false;
}
项目:BlockBunny    文件:Play.java   
/**
 * Creates box2d bodies for all non-null tiles
 * in the specified layer and assigns the specified
 * category bits.
 *
 * @param layer the layer being read
 * @param bits  category bits assigned to fixtures
 */
private void createBlocks(TiledMapTileLayer layer, short bits) {

    // tile size
    float ts = layer.getTileWidth();

    // go through all cells in layer
    for (int row = 0; row < layer.getHeight(); row++) {
        for (int col = 0; col < layer.getWidth(); col++) {

            // get cell
            Cell cell = layer.getCell(col, row);

            // check that there is a cell
            if (cell == null) continue;
            if (cell.getTile() == null) continue;

            // create body from cell
            BodyDef bdef = new BodyDef();
            bdef.type = BodyType.StaticBody;
            bdef.position.set((col + 0.5f) * ts / PPM, (row + 0.5f) * ts / PPM);
            ChainShape cs = new ChainShape();
            Vector2[] v = new Vector2[3];
            v[0] = new Vector2(-ts / 2 / PPM, -ts / 2 / PPM);
            v[1] = new Vector2(-ts / 2 / PPM, ts / 2 / PPM);
            v[2] = new Vector2(ts / 2 / PPM, ts / 2 / PPM);
            cs.createChain(v);
            FixtureDef fd = new FixtureDef();
            fd.friction = 0;
            fd.shape = cs;
            fd.filter.categoryBits = bits;
            fd.filter.maskBits = B2DVars.BIT_PLAYER;
            world.createBody(bdef).createFixture(fd);
            cs.dispose();

        }
    }

}
项目:TTmath    文件:Player.java   
private void checkDoor(float x, float y) {
    Cell cell = collisionLayer.getCell((int) x, (int) y);
    if(cell != null && cell.getTile().getProperties().containsKey("door")){
        System.out.println("found door");
        //set doorCell to cell and doorFound true
        doorCell  = cell;
        doorFound = true;
    }
    else if(cell != null && cell.getTile().getProperties().containsKey("finaldoor")){
        System.out.println("found final door");
        //set doorCell to cell and doorFound true
        doorCell = cell;
        finalDoorFound = true;
    }
}
项目:libgdxcn    文件:BaseTmxMapLoader.java   
protected void loadTileLayer (TiledMap map, Element element) {
    if (element.getName().equals("layer")) {
        String name = element.getAttribute("name", null);
        int width = element.getIntAttribute("width", 0);
        int height = element.getIntAttribute("height", 0);
        int tileWidth = element.getParent().getIntAttribute("tilewidth", 0);
        int tileHeight = element.getParent().getIntAttribute("tileheight", 0);
        boolean visible = element.getIntAttribute("visible", 1) == 1;
        float opacity = element.getFloatAttribute("opacity", 1.0f);
        TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight);
        layer.setVisible(visible);
        layer.setOpacity(opacity);
        layer.setName(name);

        int[] ids = getTileIds(element, width, height);
        TiledMapTileSets tilesets = map.getTileSets();
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                int id = ids[y * width + x];
                boolean flipHorizontally = ((id & FLAG_FLIP_HORIZONTALLY) != 0);
                boolean flipVertically = ((id & FLAG_FLIP_VERTICALLY) != 0);
                boolean flipDiagonally = ((id & FLAG_FLIP_DIAGONALLY) != 0);

                TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR);
                if (tile != null) {
                    Cell cell = createTileLayerCell(flipHorizontally, flipVertically, flipDiagonally);
                    cell.setTile(tile);
                    layer.setCell(x, height - 1 - y, cell);
                }
            }
        }

        Element properties = element.getChildByName("properties");
        if (properties != null) {
            loadProperties(layer.getProperties(), properties);
        }
        map.getLayers().add(layer);
    }
}
项目: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);
}
项目:libgdxcn    文件:SuperKoalio.java   
private void getTiles (int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {
    TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(1);
    rectPool.freeAll(tiles);
    tiles.clear();
    for (int y = startY; y <= endY; y++) {
        for (int x = startX; x <= endX; x++) {
            Cell cell = layer.getCell(x, y);
            if (cell != null) {
                Rectangle rect = rectPool.obtain();
                rect.set(x, y, 1, 1);
                tiles.add(rect);
            }
        }
    }
}
项目:libgdxcn    文件:TiledMapBench.java   
@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);

}
项目:Missing_Words    文件:World.java   
private void placePlayers() {
    Cell cell = new Cell();

    cell = tokenLayer.getCell((int) arraySquares.get(playerPosition).x, (int) arraySquares.get(playerPosition).y);

    cell.setTile(playerTile);

    if (!missingWords.isSinglePlayer()) {  // Si no es modo SINGLEPLAYER, no colocamos al npc       
        cell = tokenLayer.getCell((int) arraySquares.get(npcPosition).x, (int) arraySquares.get(npcPosition).y);
        cell.setTile(npcTile);
    }
}
项目: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);
                }
            }
        }
    }
}
项目:shadow-engine    文件:Level.java   
protected GameObject getGameObject(int ln, int x, int y, Cell cell) {
    int tid = cell.getTile().getId();
    String type = cell.getTile().getProperties().get("type", String.class);
    String subtype = cell.getTile().getProperties().get("subtype", String.class);

    GameObject obj = ShadowMap.convert(x, y, layers.get(ln), tid, type, subtype);

    if (obj instanceof Player) {
        player = (Player) obj;
    }

    return obj;
}
项目:Secludedness    文件:Level.java   
private boolean checkCollidingWithLayer(TiledMapTileLayer layer, float xPosition, float yPosition, boolean remove) {
    int xCell = (int) (xPosition / TILE_SIZE);
    int yCell = (int) (yPosition / TILE_SIZE);
    Cell cell = layer.getCell(xCell, yCell);
    if (remove){
        layer.setCell(xCell, yCell, null);
    }
    return cell != null && cell.getTile() != null;
}
项目:KyperBox    文件:TilemapLayerObject.java   
public Cell getCellAt(float x, float y) {
    return tiles.getCell((int)x,(int)y);
}
项目:KyperBox    文件:TilemapLayerObject.java   
public Cell getCell() {
    return cell;
}
项目:Mario-Libgdx    文件:TmxCell.java   
public TmxCell(Cell cell, int x, int y) {
    super();
    this.cell = cell;
    this.x = x;
    this.y = y;
}
项目:Mario-Libgdx    文件:TmxCell.java   
public Cell getCell() {
    return cell;
}