kts.Graphic

Name

kts.Graphic – create a new Graphic

Synopsis

result = kts.Graphic(filename)

result = kts.Graphic(filename, r, g, b)

result = kts.Graphic(filename, r, g, b, x, y)

result = kts.Graphic(filename, r, g, b, x, y, size_num, size_denom)

Description

A "Graphic" represents a single graphic image (or sprite) used in the game.

Graphics are loaded from BMP files (other formats are not currently supported). The file can either be one of the BMP files shipped with the game (in the knights_data/client/std_files folder), or it can be a custom image file included as part of a Knights mod. (In the latter case, the image data will automatically be downloaded to the client in network games, so there is no need to install the mod on each player's computer individually.)

To create a Graphic, kts.Graphic is called. The first parameter is always the filename. If this begins with a "+" character, then it refers to one of the std_files shipped with the game, otherwise it refers to a file included as part of the current mod.

If the r, g and b parameters are included (and set to values between 0 and 255), then the corresponding RGB colour is interpreted as a "transparency key" i.e. pixels of that exact colour will be considered transparent. (This is needed because the BMP format does not support transparency!)

If x and y are included then the "handle" position for the graphic is set to that location (relative to the top-left of the image).

If size_num and size_denom are included then the image will be scaled by the ratio size_num / size_denom before being displayed. (This is an experimental feature, and as far as I know, nothing is using it currently.)

Once a Graphic is created, it can be used for things like creating ItemTypes or Tiles, or several different Graphics can be assembled into an Anim or Overlay.

Return Value

The return value is the newly created Graphic (a Lua userdata object).

Errors

Errors can occur if the input parameters are incorrect or invalid.

Bugs

The correct values to use for the "handle position" parameters (x and y) are not particularly clear. Perhaps some kind of graphic/anim/overlay editor tool should be created.

See Also

kts.Anim

kts.Overlay