ShapeRenderer

class ShapeRenderer(val batch: Batch, val slice: TextureSlice = Textures.white)

Draws lines, shapes, and paths using a Batch for optimal performance.

Line mitering can be performed when drawing polygons and paths, see JoinType for options.

Also includes an option to snap lines to the center of pixels.

Ported from Shape Drawer by earlygrey

Author

Colton Daily

Parameters

batch

the batch used to batch draw calls with

slice

a 1x1 slice of a texture. Generally a single white pixel.

Constructors

Link copied to clipboard
fun ShapeRenderer(batch: Batch, slice: TextureSlice = Textures.white)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun circle(center: Vec2f, radius: Float, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, color: Float = colorBits)
fun circle(x: Float, y: Float, radius: Float, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, color: Float = colorBits)

Draws a circle around the specified point with the given radius.

Link copied to clipboard
fun ellipse(center: Vec2f, radius: Vec2f, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, color: Float = colorBits)
fun ellipse(center: Vec2f, rx: Float, ry: Float = rx, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, color: Float = colorBits)

Draws an ellipse around the specified point with the given radius's.

fun ellipse(x: Float, y: Float, rx: Float, ry: Float = rx, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, color: Float = colorBits)

Draws an ellipse as a stretched regular polygon estimating the number of sides required (see estimateSidesRequired) to appear smooth enough based on the pixel size that has been set.

Link copied to clipboard
fun filledCircle(center: Vec2f, radius: Float, rotation: Angle = 0.radians, color: Float = colorBits)
fun filledCircle(x: Float, y: Float, radius: Float, rotation: Angle = 0.radians, color: Float = colorBits)

Draws a filled circle as a stretched regular polygon estimating the number of sides required (see estimateSidesRequired) to appear smooth enough based on the pixel size that has been set.

Link copied to clipboard
fun filledEllipse(center: Vec2f, radius: Vec2f, rotation: Angle = 0.radians, innerColor: Float = colorBits, outerColor: Float = colorBits)
fun filledEllipse(x: Float, y: Float, rx: Float, ry: Float = rx, rotation: Angle = 0.radians, innerColor: Float = colorBits, outerColor: Float = colorBits)

Draws a filled ellipse as a stretched regular polygon estimating the number of sides required (see estimateSidesRequired) to appear smooth enough based on the pixel size that has been set.

Link copied to clipboard
fun filledPolygon(vertices: FloatArray, triangles: ShortArray)
fun filledPolygon(vertices: FloatArray, offset: Int = 0, count: Int = vertices.size)

Draws a filled polygon used the specified vertices.

fun filledPolygon(center: Vec2f, sides: Int, scaleX: Float, scaleY: Float = scaleX, rotation: Angle = 0.radians, innerColor: Float = colorBits, outerColor: Float = colorBits)
fun filledPolygon(x: Float, y: Float, sides: Int, scaleX: Float, scaleY: Float = scaleX, rotation: Angle = 0.radians, innerColor: Float = colorBits, outerColor: Float = colorBits)

Draws a filled polygon.

Link copied to clipboard
fun filledRectangle(rect: Rect, rotation: Angle = 0.radians, color: Float = colorBits, color2: Float = color, color3: Float = color2, color4: Float = color3)
fun filledRectangle(position: Vec2f, width: Float, height: Float, rotation: Angle = 0.radians, color: Float = colorBits, color2: Float = color, color3: Float = color2, color4: Float = color3)
fun filledRectangle(x: Float, y: Float, width: Float, height: Float, rotation: Angle = 0.radians, color: Float = colorBits, color2: Float = color, color3: Float = color2, color4: Float = color3)

Draws a filled rectangle.

Link copied to clipboard
fun filledTriangle(v1: Vec2f, v2: Vec2f, v3: Vec3f, color: Float = colorBits, color2: Float = color, color3: Float = color2)
fun filledTriangle(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float, color: Float = colorBits, color2: Float = color, color3: Float = color2)

Draws a filled triangle at the specified points.

Link copied to clipboard
fun line(v1: Vec2f, v2: Vec2f, color: Color, color2: Color = color, thickness: Int = this.thickness, snap: Boolean = this.snap)
fun line(v1: Vec2f, v2: Vec2f, colorBits: Float = this.colorBits, colorBits2: Float = colorBits, thickness: Int = this.thickness, snap: Boolean = this.snap)
fun line(x: Float, y: Float, x2: Float, y2: Float, color: Color, color2: Color = color, thickness: Int = this.thickness, snap: Boolean = this.snap)
fun line(x: Float, y: Float, x2: Float, y2: Float, colorBits: Float = this.colorBits, colorBits2: Float = colorBits, thickness: Int = this.thickness, snap: Boolean = this.snap)

Draws a line from point A to point B.

Link copied to clipboard
fun path(pathPoints: List<Vec2f>, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, open: Boolean = true, color: Float = colorBits)

Draws a path by drawing a line between each point and the next.

fun path(pathPoints: FloatArray, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.SMOOTH else JoinType.NONE, start: Int = 0, end: Int = pathPoints.size, open: Boolean = true, color: Float = colorBits)

Draws a path by drawing al ine between each point and the next. See path for details.

Link copied to clipboard
fun polygon(center: Vec2f, sides: Int, scaleX: Float, scaleY: Float = scaleX, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.POINTY else JoinType.NONE, color: Float = colorBits)
fun polygon(x: Float, y: Float, sides: Int, scaleX: Float, scaleY: Float = scaleX, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.POINTY else JoinType.NONE, color: Float = colorBits)

Draws a regular polygon by drawing lines between the vertices

Link copied to clipboard
fun rectangle(rect: Rect, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = JoinType.POINTY, color: Float = colorBits)
fun rectangle(position: Vec2f, width: Float, height: Float, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = JoinType.POINTY, color: Float = colorBits)
fun rectangle(x: Float, y: Float, width: Float, height: Float, rotation: Angle = 0.radians, thickness: Int = this.thickness, joinType: JoinType = JoinType.POINTY, color: Float = colorBits)

Draws a rectangle.

Link copied to clipboard
fun triangle(v1: Vec2f, v2: Vec2f, v3: Vec3f, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.POINTY else JoinType.NONE, color: Float = colorBits)
fun triangle(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float, thickness: Int = this.thickness, joinType: JoinType = if (isJoinNecessary(thickness)) JoinType.POINTY else JoinType.NONE, color: Float = colorBits)

Draws a triangle at the specified points.

Link copied to clipboard
fun updatePixelSize(context: Context)

Uses the current projection and transformation matrices of Batch to calculate the size of the screen pixel along the x-axis in world units, and calls sets the pixelSize with that value.

Properties

Link copied to clipboard
Link copied to clipboard

The packed color to be used when drawing polygons. See Color.toFloatBits.

Link copied to clipboard

The current pixel size in world units.

Link copied to clipboard

The SideEstimator used to calculate the number of sides. Defaults to DefaultSideEstimator.

Link copied to clipboard
Link copied to clipboard
var snap: Boolean = false

Whether line endpoints are snapped to the center of pixels by default.

Link copied to clipboard
var thickness: Int = 1

The default thickness, in world units, of lines and outlines when drawing when thickness is not specified