Skip to content

Image

const image = require("@vectarine/image")
export type ImageResource = ...
ImageResource:draw(pos: Pos, size: Direction, color: Vec4.Vec4?): ()

Draws the image at the position and with the size given You can optionally tint the image with the given color. The color of the pixels of the image are multiplied by the tint.

ImageResource:drawPart(
dest_p1: Pos,
dest_p2: Pos,
dest_p3: Pos,
dest_p4: Pos,
src_pos: Vec.Vec2,
src_size: Vec.Vec2,
color: Vec4.Vec4?,
): Vec.Vec2

Draws a rectangular part of the image delimited by a position and a size This section is deformed to match the quadrilateral delimited by the 4 destination points You can swap the destination points to rotate, flip the image. Use src_pos = V2(0, 0) and src_size = V2(1, 1) to draw the full image.

ImageResource:getSize(): Vec.Vec2

Gets the size of the image in pixels

ImageResource:withTileset(tileset: Tile.TilesetResource): ImageWithTileset

Combine an image with a tileset to be able to easily draw tiles from the image. Methods using the ImageWithTileset require that both the image and the tileset are loaded. They provide convenience over having to specify src_pos and src_size using drawPart.

export type ImageWithTileset = ...
ImageWithTileset:drawTile(
tileIdOrType: number | string,
pos: Pos,
size: Direction,
color: Vec4.Vec4?,
): ()

Draw a part of the image corresponding to the tile specified by its id or type. If there are multiple tiles with the same type, one of them will be choosen in an unspecified manner.

ImageWithTileset:drawTileQuad(
tileIdOrType: number | string,
dest_p1: Pos,
dest_p2: Pos,
dest_p3: Pos,
dest_p4: Pos,
color: Vec4.Vec4?,
): ()

Draw a part of the image corresponding to the tile specified by its id or type. The part of the image corresponding to the tile is deformed to match the quadrilateral delimited by the 4 destination points. If there are multiple tiles with the same type, one of them will be choosen in an unspecified manner.

type Pos = ...
type Direction = ...