amour - a basic scene graph library
Posted: Sun Oct 28, 2018 8:01 am
As the title suggests, amour supports creating a scene graph, basically a hierachical structure for drawables.
GitHub: https://github.com/flatgames/amour
Documents: https://github.com/flatgames/amour/wiki
A piece of sample code:
Result:
Dependencies:
GitHub: https://github.com/flatgames/amour
Documents: https://github.com/flatgames/amour/wiki
A piece of sample code:
Code: Select all
local Scene = require 'amour.scene'
local Rect = require 'amour.rect'
local Text = require 'amour.text'
local flux = require 'flux'
local scene
function love.load()
scene = Scene(480, 320, 'expand')
local bigRect = Rect(scene.w * 0.5, scene.h * 0.5,
200, 200, { 0, 0.5, 1, 1 })
scene:addChild(bigRect)
local topLeftRect = Rect(10, 10, 50, 50, { 1, 1, 1, 1 })
topLeftRect:updateAnchor(0, 0)
bigRect:addChild(topLeftRect)
local bottomText = Text(bigRect.w * 0.5, bigRect.h - 10,
love.graphics.newFont(12), 'Bottom Text',
{ 1, 1, 1, 1})
bottomText:updateAnchor(0.5, 1)
bigRect:addChild(bottomText)
bigRect:flux(10, { r = math.pi * 2 })
end
function love.update(dt)
flux.update(dt)
end
function love.draw()
scene:draw()
end
function love.keypressed(key, scancode, isrepeat)
if key == 'escape' then
love.event.quit()
end
end
Dependencies:
- classic: https://github.com/rxi/classic
- flux (optional): https://github.com/rxi/flux
- No z-index: nodes are rendered in the order they are stored in their parent's child list. This is to make the library simple.
- Transform values must be set using an updateXXX function instead of setting them directly. I hope to fix this in a future update.