Skip to main content

Spritebatch

Allows drawing a batch of sprites (quads (regions)) from an image in a single call.

Which gives huge performance boost, especially if the regions are static (not changing).

Methods

caution

Object methods should be called using the : operator. Which passes the object itself as a parameter before all the other specified parameters. That is necessary for object methods to work efficiently.

For example to call the method shutdown on the object myComputer the both ways would work:

myComputer:shutdown()

spriteBatch:add

Add a sprite (quad) to the batch.

spriteId = spriteBatch:add(quad, x, y, rotation, scaleX, scaleY, originX, originY, shearX, shearY)
ParameterTypeDefaultNote
quadQuad⚠️ required
xnumber0
ynumber0
rotationnumber0in radians.
scaleXnumber11 to preserve scale.
scaleYnumber11 to preserve scale.
originXnumber0
originYnumber0
shearXnumber0
shearYnumber0
ReturnTypeNote
spriteIdnumbercan be used for removing the sprite later.

spriteBatch:set

Modify a sprite in the batch.

spriteBatch = spriteBatch:set(spriteId, quad, x, y, rotation, scaleX, scaleY, originX, originY, shearX, shearY)
ParameterTypeDefaultNote
spriteIdnumber⚠️ requiredto update
quadQuad⚠️ requiredto replace existing one (can be the same one)
xnumber0
ynumber0
rotationnumber0in radians.
scaleXnumber11 to preserve scale.
scaleYnumber11 to preserve scale.
originXnumber0
originYnumber0
shearXnumber0
shearYnumber0
ReturnTypeNote
spriteBatchSpriteBatchthe object itself. allows to do chain calls.

spriteBatch:clear

Clear the sprites from the buffer (remove them all).

spriteBatch = spriteBatch:clear()
ReturnTypeNote
spriteBatchSpriteBatchthe object itself. allows to do chain calls.

spriteBatch:draw

Draw the sprite batch into the screen.

spriteBatch = spriteBatch:draw(x, y, rotation, scaleX, scaleY, quad)
ParameterTypeDefaultNote
xnumber0
ynumber0
rotationnumber0in radians.
scaleXnumber11 to preserve scale.
scaleYnumber11 to preserve scale.
quadQuad, nilnila quad to draw only a region from the spritebatch. otherwise the full spritebatch is drawn.
ReturnTypeNote
spriteBatchSpriteBatchthe object itself. allows to do chain calls.

spriteBatch:flush

Immediately refresh the batch data. (Sometimes necessary).

sb = spriteBatch:flush()
ReturnTypeNote
spriteBatchSpriteBatchthe object itself. allows to do chain calls.

spriteBatch:getCount

Get the current number of sprites in the batch.

count = spriteBatch:getCount()
ReturnTypeNote
countnumber

spriteBatch:getBufferSize

Get the maximum number of sprites the batch can contain.

capacity = spriteBatch:getBufferSize()
ReturnTypeNote
capacitynumber

spriteBatch:setBufferSize

Set the maximum number of sprites the batch can contain.

spriteBatch = spriteBatch:setBufferSize(capacity)
ParameterTypeDefaultNote
capacitynumber⚠️ requiredmust be positive integer
ReturnTypeNote
spriteBatchSpriteBatchthe object itself. allows to do chain calls.

spriteBatch:usage

The hint set during the batch creation for doing optimizations internally.

usage = spriteBatch:usage()
ReturnTypeNote
usagestringenum: 'dynamic', 'static', 'stream'.

spriteBatch:type

Get the type of the object as a string.

danger

This method most likely will be removed in a future version.

type = spriteBatch:type()
ReturnTypeNote
objectTypestringspritebatch

spriteBatch:typeOf

Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

danger

This method most likely will be removed in a future version.

isIt = spriteBatch:typeOf(type)
ParameterTypeDefaultNote
typestring⚠️ required
ReturnTypeNote
isItboolean'GPU', 'spritebatch', 'GPU.spritebatch', 'LK12' would give true.