Example usage for com.badlogic.gdx.graphics.g2d.tiled TiledLayer getWidth

List of usage examples for com.badlogic.gdx.graphics.g2d.tiled TiledLayer getWidth

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d.tiled TiledLayer getWidth.

Prototype

public int getWidth() 

Source Link

Usage

From source file:com.sertaogames.cactus2d.components.TileMapPhysics.java

License:Open Source License

private void createFromBlocks() {
    TiledLayer physicsLayer = null;
    for (TiledLayer layer : tm.tilemap.layers) {
        if (layer.name.equals(physicsLayerName))
            physicsLayer = layer;/*from   w w w  .j ava2 s.c  o  m*/
    }

    for (int i = 0; i < physicsLayer.getHeight(); i++) {
        int begin = -1;
        int last = -1;
        for (int j = 0; j < physicsLayer.getWidth(); j++) {
            int tile = physicsLayer.tiles[i][j];
            // System.out.println(tile);

            if (tile != 0) {
                last = j;
                if (begin < 0) {
                    begin = j;
                }
            }

            if ((j == physicsLayer.getWidth() - 1 || tile == 0) && last >= 0) {
                createBodyFromBlocks(begin, last, i);
                begin = -1;
                last = -1;
            }
        }
    }
}