Skip to main content

Image

An immutable drawable 2-dimensional array of pixels data.

info

To mutate, convert it into an imagedata first using image:data.

Creation

image

Create a new image that can be used for drawing.

createdImage = image(data)
ParameterTypeDefaultNote
datastring⚠️ requiredin the .lk12 image format.
ReturnTypeNote
createdImageImage

Load an ImageData into an image

Which can be done using imagedata:image.

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()

image:draw

Draws the image on the screen.

image:draw(x, y, rotation, scaleW, scaleH, quad)
ParameterTypeDefaultNote
xnumber0
ynumber0
rotationnumber0in radians.
scaleXnumber11 to preserve scale.
scaleYnumber11 to preserve scale.
quadQuad, nilnila quad to draw only a region from the image. otherwise the full image is drawn.

image:width

Get the image width.

width = image:width()
ReturnTypeNote
widthnumberin pixels.

image:height

Get the image height.

height = image:height()
ReturnTypeNote
heightnumberin pixels.

image:size

Get the image dimensions.

width, height = image:size()
ReturnTypeNote
widthnumber
heightnumber

image:quad

Create a new quad representing a region from this image.

createdQuad = image:quad(x, y, width, height)
ParameterTypeDefaultNote
xnumber⚠️ requiredof the region to represent.
ynumber⚠️ requiredof the region to represent.
widthnumber⚠️ requiredof the region to represent.
heightnumber⚠️ requiredof the region to represent.
ReturnTypeNote
createdQuadQuad

image:data

Get the imagedata object of this image, which can be used to set and get pixels of the image.

note

The calls of this function are cheap, unlike imagedata:image.

caution

Use a different name than imageData for storing the value in. As that might confuse it with the imagedata function.

imageData = image:data()
ReturnTypeNote
imageDataImageData

image:refresh

Reload the Image's contents from the ImageData used to create the image.

image:refresh()

image:batch

Use the image to create a spritebatch.

Which allows to draw a batch of sprites from this image.

spriteBatch = image:batch(capacity, usage)
ParameterTypeDefaultNote
capacitynumber1000
usagestring'static'enum: 'dynamic', 'static', 'stream'.
ReturnTypeNote
spriteBatchSpriteBatch

image:type

Get the type of the object as a string.

danger

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

objectType = image:type()
ReturnTypeNote
objectTypestringGPU.image

image:typeOf

Check 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 = image:typeOf(type)
ParameterTypeDefaultNote
typestring⚠️ required
ReturnTypeNote
isItboolean'GPU', 'image', 'GPU.image', 'LK12' would give true.