Shaku

Shaku JS

Back To Table of Content

Shapes Batch

ShapesBatch

Colored shapes renderer. Responsible to drawing a batch of basic geometric shapes with as little draw calls as possible.

Kind: global class

new ShapesBatch([batchPolygonsCount])

Create the sprites batch.

Param Type Description
[batchPolygonsCount] Number Internal buffers size, in polygons count (polygon = 3 vertices). Bigger value = faster rendering but more RAM.

shapesBatch.onOverflow : function

Optional method to trigger when shapes batch overflows and can’t contain any more polygons.

Kind: instance property of ShapesBatch

shapesBatch.snapPixels : Boolean

If true, will floor vertices positions before pushing them to batch.

Kind: instance property of ShapesBatch

shapesBatch.isDestroyed

Kind: instance property of ShapesBatch

shapesBatch.defaultEffect

Kind: instance property of ShapesBatch

shapesBatch.polygonsInBatch ⇒ Number

Get how many polygons are currently in batch.

Kind: instance property of ShapesBatch
Returns: Number - Polygons in batch count.

shapesBatch.maxPolygonsCount ⇒ Number

Get how many polygons this sprite batch can contain.

Kind: instance property of ShapesBatch
Returns: Number - Max polygons count.

shapesBatch.isFull ⇒ Boolean

Check if this batch is full.

Kind: instance property of ShapesBatch
Returns: Boolean - True if batch is full.

shapesBatch.clear()

Kind: instance method of ShapesBatch

shapesBatch.destroy()

Kind: instance method of ShapesBatch

shapesBatch.drawLine(fromPoint, toPoint, color, [width])

Draw a line between two points. This method actually uses a rectangle internally, which is less efficient than using a proper LinesBatch, but have the advantage of supporting width.

Kind: instance method of ShapesBatch

Param Type Description
fromPoint Vector2 Starting position.
toPoint Vector2 Ending position.
color Color Line color.
[width] Number Line width.

shapesBatch.drawVertices(vertices)

Push vertices to drawing batch.

Kind: instance method of ShapesBatch

Param Type Description
vertices Array.<Vertex> Vertices to push. Vertices count must be dividable by 3 to keep the batch consistent of polygons.

shapesBatch.drawQuad(position, size, color, [rotation], [origin], [skew])

Add a rectangle to draw.

Kind: instance method of ShapesBatch

Param Type Description
position Vector2 | Vector3 Drawing position (at origin). If vector3 is provided, will pass z value to the shader code position attribute.
size Vector2 | Vector3 | Number Drawing size. If vector3 is provided, will pass z value to the shader code position attribute for the bottom vertices, as position.z + size.z.
color Color | Array.<Color> | undefined Rectangle color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left.
[rotation] Number Rotate rectangle.
[origin] Vector2 Drawing origin. This will be the point at ‘position’ and rotation origin.
[skew] Vector2 Skew the drawing corners on X and Y axis, around the origin point.

shapesBatch.addPoint(position, color)

Adds a 1x1 point.

Kind: instance method of ShapesBatch

Param Type Description
position Vector2 | Vector3 Point position.
color Color Point color.

shapesBatch.drawRectangle(destRect, color, [rotation], [origin])

Add a rectangle that covers a given destination rectangle.

Kind: instance method of ShapesBatch

Param Type Description
destRect Rectangle | Vector2 Destination rectangle to draw on. If vector is provided, will draw from 0,0 with vector as size.
color Color | Array.<Color> | undefined Rectangle color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left.
[rotation] Number Rotate rectangle.
[origin] Vector2 Drawing origin. This will be the point at ‘position’ and rotation origin.

shapesBatch.drawCircle(circle, color, [segmentsCount], [outsideColor], ratio, [rotation])

Draw a colored circle.

Kind: instance method of ShapesBatch

Param Type Description
circle Circle Circle to draw.
color Color Circle fill color.
[segmentsCount] Number How many segments to build the circle from (more segments = smoother circle).
[outsideColor] Color If provided, will create a gradient-colored circle and this value will be the outter side color.
ratio Number | Vector2 If procided, will scale the circle on X and Y axis to turn it into an oval. If a number is provided, will use this number to scale Y axis.
[rotation] Number If provided will rotate the oval / circle.