Module overlay
A layer that sprites or text can manually be drawn in.
Overlay extends BoundObject
Properties
| scene | (read only) The Scene that contains Overlay |
| track_entity | The Entity tracked by Overlay. |
| track_entity_edge | The edge of the track_entity used to determine {0, 0} |
Class Methods
| Overlay:new () | Create a new Overlay |
Instance Methods
| overlay:add_sprite (sprite) | Add a Sprite to the Overlay. |
| overlay:draw_string (opts) | Draw a string to Overlay. |
| overlay:draw_sprite (opts) | Draw a Sprite to Overlay. |
Configuration
| font_name | The file name of the TTF or OTF font to use when drawing strings. |
| font_size | The font size in pixels to use when drawing strings. |
Hooks
| update (self) | Called once each frame during the Scene's update cycle. |
| render (self) | Called once each frame during the Scene's render cycle. |
Properties
Properties. Significant fields on an instance.- scene
-
(read only) The Scene that contains
Overlay - track_entity
-
The Entity tracked by
Overlay.This will make point
{0, 0}track_entity_edge's point on thetrack_entity's bounding box. - track_entity_edge
-
The edge of the track_entity used to determine
{0, 0}The edges are relative to the bounding box as follows:0---1---2 | | | 3---4---5 | | | 6---7---8(
0is top left,4is center,8is bottom right)
Class Methods
Class Methods. Must be called onClass, with a capital leading character.
e.g. Class:method("foo")
Instance Methods
Instance Methods. Must be called on an instance ofClass.
e.g. instance:method("foo")
- overlay:add_sprite (sprite)
-
Add a Sprite to the
Overlay.The main reason for this is so sprite can be updated. If you do not do this, SpriteAnimations will not advance.
Parameters:
- sprite Sprite The sprite to add
Returns:
-
nil
- overlay:draw_string (opts)
-
Draw a string to
Overlay.This function is called with an "
opts" parameter table. The parameters do not have to be in order.Valid Options:
string = The string to draw. (required)
color={r, g, b, a}vector representing the text color. Default{1, 1, 1, 1}(white).origin={x, y}baseline origin point relative to the screen center or entity edge in pixels. Default{0, 0}align= The text alignment. Can be"left","right"or"center". Default"left"shadow_color={r, g, b, a}vector representing the shadow color. Defaultnil.shadow_offset={x, y}vector representing the shadow offset in pixels. Defaultnil
Parameters:
- opts table The named parameters.
Returns:
-
nil
Usage:
-- Red text with a white shadow, drawn in the center of the screen. overlay:draw_string({ string = "Hello World!", align = "center", color = {1, 0, 0, 1}, origin = {0, 0}, shadow_color = {1, 1, 1, 1}, shadow_offset = {0, 0} })
- overlay:draw_sprite (opts)
-
Draw a Sprite to
Overlay.This function is called with an "
opts" parameter table. The parameters do not have to be in order.Valid Options:
color={r, g, b, a}vector representing the background color. Default{0, 0, 0, 0}(clear).center={x, y}point relative to the screen center or entity edge in pixels. Default{0, 0}rotation= The angle of the sprite in degrees. Default0scale= Either a number or an{x, y}vector representing a scale factor. Default1
Parameters:
- opts table The named parameters.
Returns:
-
nil
Usage:
local mysprite = MySprite:new() overlay:draw_sprite({ sprite = mysprite, center = {0, -100}, rotation = 180, scale = {2, 1} })
Configuration
Configuration. Required by subclass declarations. Used when instantiating concrete subclasses.- font_name
-
The file name of the TTF or OTF font to use when drawing strings.
Defaults to
nil - font_size
-
The font size in pixels to use when drawing strings.
Defaults to
0
Hooks
Hooks. Callbacks implemented in subclasses to customize behavior. Hooks are called on individual instances.- update (self)
-
Called once each frame during the Scene's update cycle. Modify values to
display in this hook.
Parameters:
- self
Overlay
The
Overlayinstance
- self
Overlay
The
- render (self)
-
Called once each frame during the Scene's render cycle. Perform draw
calls in this hook.
Parameters:
- self
Overlay
The
Overlayinstance
- self
Overlay
The