Hello world - ecbambrick/SimpleEntityComponentSystem GitHub Wiki
main.lua
note: note: the following example uses LÖVE.
function love.load()
-- initialize Secs and individual systems
secs = require "secs"
require "systems.draw"
-- define components with some default values
secs.component("position", { x = 0, y = 0 })
secs.component("text", { text = "" })
-- define an entity type
secs.type("textEntities", "position", "text")
-- initialize an entity
secs.entity(
{"position", { x = 100, y = 100 }},
{"text", { text = "Hello World" }}
)
end
function love.update(dt)
secs.update(dt)
end
function love.draw()
secs.draw()
end
systems\draw.lua
secs.rendersystem("draw", 1, function()
for e in pairs(secs.query("textEntities")) do
love.graphics.print(e.text.text, e.position.x, e.position.y)
end
end)