-
Notifications
You must be signed in to change notification settings - Fork 0
Home
amour - a basic scene graph library for LÖVE.
Just copy amour into the root folder of your game.
- No support for z-index: child nodes added later will be drawn later.
- Although transform properties like
x,y,r, etc. can be read directly, they must be set viaupdateXXX()functions or the transforms won't be updated. - Usage of
fluxon transform properties must be done vianode:flux()instead offlux.to(node, ...)to make sure node transform is updated.
local Scene = require 'amour.scene'
local Rect = require 'amour.rect'
local Text = require 'amour.text'
local scene
function love.load()
scene = Scene(480, 320)
local bg = Rect(scene.w * 0.5, scene.h * 0.5, scene.w, scene.h, { 0.2, 0.2, 0.2, 1 })
scene:addChild(bg)
local title = Text(scene.w * 0.5, 10, 14, "Je t'aime!", { 1, 0, 0, 1})
title:updateAnchor(0.5, 0)
scene:addChild(title)
end
function love.draw()
scene:draw()
endPosition of the node.
Size of the node.
Rotation of the node (in radians).
Scale of the node.
Anchor point of the node. Default value is (0.5, 0.5).
If set to false, the node and its children will not be rendered.
Creates and returns a node object.
-
x: x coordinate -
y: y coordinate -
w: width -
h: height
Adds a child node to this node.
-
node: child node to add -
index: used when child node is to be inserted at a specific place in the child list
Removes a child node from this node.
-
node: child node to remove
Moves a child node to a new place in the child list.
-
node: child node to move -
index: new index of the child node
Returns the left X and top Y of the node. Useful in render function.
Draws the node.
To be overriden in derived class to perform actual rendering.
Sets new values for x and y, and updates the node transform.
Sets new value for r, and updates the node transform.
Sets new values for w and h, and updates the node transform.
Sets new values for sx and sy, and updates the node transform.
Sets new values for ax and ay, and updates the node transform.
(USED INTERNALLY) Updates the node transform according to current transform values.
-
needPropagation: iftrue, calls this function on all children.
Returns true if this node contains the point at global coordinates (gx, gy).
Performs a tween using flux library and returns the tween object.
-
duration: how long the tween lasts, in seconds -
changes: a table of changes to the node's fields -
group: optional flux tween group
Any tweens on transform values of a node should be done via this function instead of flux.to in order to update the transform accordingly.
Creates a scene that adapts to current dimensions of the game. The scene node may be scaled to match the game window.
-
designWidth: design width -
designHeight: design height -
sizeMode(default'expand'): how the scene adapts to window size-
'expand': scaled to smaller dimension, the other will be expanded to fill -
'cut': scaled to greater dimension, the other will be cut to fit -
'width': prioritize width, height will be expanded or cut accordingly -
'height': prioritize height, width will be expanded or cut accordingly
-
Creates a pixel-perfect scene. Design size will be multiplied with an integral value big enough that the result is less than or equal to the screen size. The scene will then be expanded to fill the whole screen.
-
designWidth: minimum design width -
designHeight: minimum design height
Current color of the rectangle, in the form { r, g, b, a }.
Creates and returns a rectangular node.
-
x: x coordinate -
y: y coordinate -
w: width -
h: height -
color(default{1,1,1,1}): color of the rectangle -
mode(default'fill'): draw mode,'fill'or'line' -
lineWidth(default1): line width if mode is line
Current color of the text, in the form { r, g, b, a }.
Creates and returns a text node.
-
x: x coordinate -
y: y coordinate -
font: a font object, or just font size -
textString: initial text string -
color(default{1,1,1,1}): text color
Returns current text string.
Sets new text string.
-
textString: new text string, or a coloredtext table as defined by LÖVE -
wrapLimit: maximum width before line-break happens -
alignMode: text alignment,'left','center'or'right'
Current color of the image, in the form { r, g, b, a }.
Creates and returns an image node.
-
x: x coordinate -
y: y coordinate -
image: an Image object or path to the image file -
color(default{1,1,1,1}): text color
Current color of the quad, in the form { r, g, b, a }.
Creates and returns a quad node.
-
x: x coordinate -
y: y coordinate -
qx: x coordinate of the quad in the image -
qy: y coordinate of the quad in the image -
qw: width of the quad -
qh: height of the quad -
image: an Image object or path to the image file -
color(default{1,1,1,1}): text color
Wrapper is a generic node that supports rendering of custom drawable types.
Creates and returns a wrapper node.
-
x: x coordinate -
y: y coordinate -
w: width -
h: height -
target: drawable object to render -
renderer: custom render function with the signaturefunction(target, x0, y0)
Example of using Wrapper to draw a gradient mesh:
function love.load()
local mesh = love.graphics.newMesh(
{
{ 0,0, 0,0, 1,1,1,1 },
{ 100,0, 1,0, 1,1,1,1 },
{ 100,100, 1,1, 1,0,0,1 },
{ 0,100, 0,1, 1,0,0,1 },
}, 'fan')
wrapper = Wrapper(120, 120, 100, 100, mesh,
function(target, x0, y0)
love.graphics.draw(target, x0, y0)
end)
end
-- ...
function love.draw()
wrapper:draw()
end