Module Element
This is a description of what is expected in an element class.
IMPORTANT: Your class should inherit from the element class. This means that any methods defined on that class need to be compatible with or overridden by your class!
Functions
load (pop) | Optional: Called during pop.load() with a reference to Pop.Box. |
wrap (pop) | Optional: Called during pop.load() to allow a custom wrapper function
to be created for your element class. |
update (dt) | Optional: Called from pop.update() if data.update and a child of
pop.screen . |
draw () | Optional: Called from pop.draw() if data.draw and a child of
pop.screen . |
mousemoved (x, y, dx, dy) | Optional: Called from pop.mousemoved() if in LOVE >= 0.10.0 and your
element is focused. |
mousepressed (x, y, button) | Optional: Called from pop.mousepressed() if a mouse button was pressed
over your element. |
Tables
data | Every object has a data field with pre-defined values. |
Fields
parent | The parent element of this element. |
child | The child elements of this element. |
Functions
- load (pop)
-
Optional: Called during
pop.load()
with a reference to Pop.Box.Parameters:
- pop module The Pop.Box module.
- wrap (pop)
-
Optional: Called during
pop.load()
to allow a custom wrapper function to be created for your element class.Parameters:
- pop module The Pop.Box module.
Returns:
-
function
wrapper A function to be called to create an element of
this class instead of using
pop.create()
. - update (dt)
-
Optional: Called from
pop.update()
ifdata.update
and a child ofpop.screen
. Use it for any time-based updates your element may need.Parameters:
- dt number The amount of time elapsed since update was last called.
- draw ()
-
Optional: Called from
pop.draw()
ifdata.draw
and a child ofpop.screen
. Use it to draw your element. - mousemoved (x, y, dx, dy)
-
Optional: Called from
pop.mousemoved()
if in LOVE >= 0.10.0 and your element is focused.Parameters:
- x integer The x coordinate of the mouse.
- y integer The y coordinate of the mouse.
- dx number The distance on the x axis the mouse was moved.
- dy number The distance on the y axis the mouse was moved.
Returns:
-
boolean
Was the event handled?
- mousepressed (x, y, button)
-
Optional: Called from
pop.mousepressed()
if a mouse button was pressed over your element.Note: Your element must be visible (
data.draw
is true) for this method to be called.Parameters:
- x integer The x coordinate of the mouse press.
- y integer The y coordinate of the mouse press.
- button string or integer The mouse button pressed. (Type varies by LÖVE version.)
Returns:
-
boolean
Was the event handled?
Tables
- data
-
Every object has a data field with pre-defined values. Any serializable data
should be saved in this field. Ideally, any Pop.Box element can be
reconstructed from its data field.
Fields:
- parent table or false The parent of this element's data field. This will not be serialized. This is the only exception to all data being serialized.
- child table All child elements' data fields.
- x integer The left edge of your element.
- y integer The top edge of your element.
- w integer The width of your element.
- h integer The height of your element.
- update boolean Whether or not to update this element (and its children).
- draw boolean Whether or not to draw this element (and its children).
Fields
- parent
-
The parent element of this element.
- parent Element or false Parent element.
- child
-
The child elements of this element.
- child table All child elements.