Search in sources :

Example 1 with Ellipse

use of com.badlogic.gdx.math.Ellipse in project libgdx by libgdx.

the class TiledMapObjectLoadingTest method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    shapeRenderer.setColor(Color.BLUE);
    Gdx.gl20.glLineWidth(2);
    MapLayer layer = map.getLayers().get("Objects");
    AnimatedTiledMapTile.updateAnimationBaseTime();
    for (MapObject mapObject : layer.getObjects()) {
        if (mapObject instanceof TiledMapTileMapObject) {
            batch.begin();
            TiledMapTileMapObject tmtObject = (TiledMapTileMapObject) mapObject;
            TextureRegion textureRegion = tmtObject.getTile().getTextureRegion();
            // TilEd rotation is clockwise, we need counter-clockwise.
            float rotation = -tmtObject.getRotation();
            float scaleX = tmtObject.getScaleX();
            float scaleY = tmtObject.getScaleY();
            float xPos = tmtObject.getX();
            float yPos = tmtObject.getY();
            textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
            batch.draw(textureRegion, xPos, yPos, tmtObject.getOriginX() * scaleX, tmtObject.getOriginY() * scaleY, textureRegion.getRegionWidth() * scaleX, textureRegion.getRegionHeight() * scaleY, 1f, 1f, rotation);
            // We flip back to the original state.
            textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
            batch.end();
        } else if (mapObject instanceof EllipseMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
            shapeRenderer.ellipse(ellipse.x, ellipse.y, ellipse.width, ellipse.height);
            shapeRenderer.end();
        } else if (mapObject instanceof RectangleMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
            shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
            shapeRenderer.end();
        } else if (mapObject instanceof PolygonMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
            Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
            shapeRenderer.polygon(polygon.getTransformedVertices());
            shapeRenderer.end();
        }
    }
    batch.begin();
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    batch.end();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PolygonMapObject(com.badlogic.gdx.maps.objects.PolygonMapObject) Ellipse(com.badlogic.gdx.math.Ellipse) RectangleMapObject(com.badlogic.gdx.maps.objects.RectangleMapObject) MapLayer(com.badlogic.gdx.maps.MapLayer) EllipseMapObject(com.badlogic.gdx.maps.objects.EllipseMapObject) Rectangle(com.badlogic.gdx.math.Rectangle) TiledMapTileMapObject(com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject) Polygon(com.badlogic.gdx.math.Polygon) MapObject(com.badlogic.gdx.maps.MapObject) TextureMapObject(com.badlogic.gdx.maps.objects.TextureMapObject) EllipseMapObject(com.badlogic.gdx.maps.objects.EllipseMapObject) TiledMapTileMapObject(com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject) RectangleMapObject(com.badlogic.gdx.maps.objects.RectangleMapObject) PolygonMapObject(com.badlogic.gdx.maps.objects.PolygonMapObject)

Aggregations

TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 MapLayer (com.badlogic.gdx.maps.MapLayer)1 MapObject (com.badlogic.gdx.maps.MapObject)1 EllipseMapObject (com.badlogic.gdx.maps.objects.EllipseMapObject)1 PolygonMapObject (com.badlogic.gdx.maps.objects.PolygonMapObject)1 RectangleMapObject (com.badlogic.gdx.maps.objects.RectangleMapObject)1 TextureMapObject (com.badlogic.gdx.maps.objects.TextureMapObject)1 TiledMapTileMapObject (com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject)1 Ellipse (com.badlogic.gdx.math.Ellipse)1 Polygon (com.badlogic.gdx.math.Polygon)1 Rectangle (com.badlogic.gdx.math.Rectangle)1