kts.Overlay – create an Overlay (set of four graphics, representing an item held by a creature)
overlay = kts.Overlay{ graphic_north, graphic_east, graphic_south, graphic_west }
Note that the parameter is a single Lua table, containing four Graphics, rather than four individual Lua parameters.
This function creates an Overlay. An Overlay is a collection of four individual Graphics, depicting an item (sword, axe, etc.) as held by a Creature. The four graphics correspond to the four directions: north, east, south and west.
The basic idea is that we do not draw separate graphics for a knight holding a sword, a knight holding an axe, a knight holding a hammer, etc. Instead, there is one "base" knight graphic, and then different "overlays" that can be superimposed on top of that: one overlay represents an axe, another a sword, another a hammer, and so on. When the game draws the overlay graphic on top of the knight graphic, then a complete image of a knight holding the appropriate weapon is formed. (The same holds for other creatures that carry weapons; in the base game, only zombies fall into this category, although other weapon-carrying monsters might be added by mods.)
To create an overlay, the kts.Overlay
function is called. The four parameters are graphics representing the appropriate weapon facing in the four possible directions. As mentioned, the game will superimpose one of these graphics on top of the appropriate Creature graphic in order to draw the creature correctly.
A new Overlay object is returned. This object can be used as the overlay
parameter when creating an ItemType.
An error will result if the parameter is not a table containing four Graphics.
If you are creating new Overlays for new weapon types, it is recommended to look at the existing BMP files (such as sword_north.bmp, axe_east.bmp and so on) to see how these have been set up. Also look at the corresponding entries in graphics.lua
(such as g_sword_north
, g_axe_east
etc.), paying particular attention to the "handle positions" (the 5th and 6th parameters to kts.Graphic
). Some trial and error might be needed in order to get the handle positions correct.
The "Axe" overlay graphics are created as follows (see graphics.lua
):
g_axe_north = kts.Graphic("+axe_north.bmp",0,0,0, -6,-4) g_axe_east = kts.Graphic("+axe_east.bmp",0,0,0, 0,-6) g_axe_south = kts.Graphic("+axe_south.bmp",0,0,0, -7, 0) g_axe_west = kts.Graphic("+axe_west.bmp",0,0,0, -4,-7)
Then, in items.lua
, when the i_axe
ItemType is created, the following line is added to the kts.ItemType
call:
overlay = kts.Overlay { g_axe_north, g_axe_east, g_axe_south, g_axe_west }
Other examples (e.g. wands, daggers, hammers) can be found in the standard Knights Lua files shipped with the game.
kts.Anim (sets the "base" creature graphics, which the overlays are drawn on top of)
kts.ItemType (this is where overlays are used)