Class catan.gui.Layer
An array of catan.gui.Sprite objects.
Tables
catan.gui.layer.TableCell | Table cell in addSpriteTable |
Methods
catan.gui.layer:new () | Create an empty layer |
catan.gui.layer:addSprite (...) | Add sprite to layer |
catan.gui.layer:addSpriteTable (t) | Add a table of sprites |
catan.gui.layer:iterSprites (f) | Iterate through sprites in layer |
Tables
- catan.gui.layer.TableCell
-
Table cell in addSpriteTable
Fields:
- 1 Drawable the drawable object
- sx number the horizontal scaling factor (default 1)
- sy number the vertical scaling factor (default sx)
- xalign string the horizontal alignment for the sprite within the cell (default 'center')
- yalign string the vertical alignment for the sprite within the cell (default 'center')
- onleftclick function left-click callback (default nil)
- onrightclick function right-click callback (default nil)
See also:
Methods
- catan.gui.layer:new ()
-
Create an empty layer
Returns:
-
catan.gui.Layer
the newly-created layer
- catan.gui.layer:addSprite (...)
-
Add sprite to layer
Parameters:
- ... arguments passed to catan.gui.Sprite:new
Returns:
-
catan.gui.Sprite
the newly-created sprite
Usage:
local sprite = layer:addSprite{ img, x = 100, y = 300, sx = 0.5, }
- catan.gui.layer:addSpriteTable (t)
-
Add a table of sprites
Parameters:
- t a table of tables of cells, which can be
either TableCell,
Drawable
ornil
.- n number number of table lines (default 1)
- m number number of table columns (default 1)
- x number the sprite table horizontal coordinate (default 0)
- y number the sprite table vertical coordinate (default 0)
- xsep number the horizontal space between sprites (default 0)
- ysep number the vertical space between sprites (default 0)
- xalign string the horizontal alignment for the whole sprite table (default 'left')
- yalign string the vertical alignment for the whole sprite table (default 'top')
- bgimg Drawable background image (default nil)
- bgmargin number background margin (default 0)
Returns:
-
catan.gui.Box
box that bounds all sprites in the table
See also:
Usage:
local box = layer:addSpriteTable{ { img11, img12, img13 }, -- 1st line { img21, img22, img23 }, -- 2nd line n = 2, m = 3, x = 700, y = 500, xsep = 10, ysep = 20, }
- t a table of tables of cells, which can be
either TableCell,
- catan.gui.layer:iterSprites (f)
-
Iterate through sprites in layer
Parameters:
- f function an iterator function to be called with each sprite
Returns:
-
the first value returned by
f
that is notfalse
ornil
Usage:
layer:iterSprites(function (sprite) sprite:draw() -- draws each sprite onto the screen end)