Skip to content

Instantly share code, notes, and snippets.

@drhayes
Created February 22, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhayes/745ed3dc110fd8c418348af5c5879a2f to your computer and use it in GitHub Desktop.
Save drhayes/745ed3dc110fd8c418348af5c5879a2f to your computer and use it in GitHub Desktop.
An ECS draw system I wrote.
local tiny = require 'lib.tiny'
local spriteAtlas = require 'core.spriteAtlas'
local lume = require 'lib.lume'
local physicsSystem = require 'systems.physics'
local config = require 'gameConfig'
function drawSystem(groupName)
groupName = groupName or 'default'
local drawSystem = tiny.processingSystem({ isDraw = true })
function drawSystem:filter(entity)
if not entity.draw then return false end
if entity.draw.group == groupName then
return true
elseif groupName == 'default' then
return true
end
return false
end
function drawSystem:onAdd(e)
e.draw = lume.extend({
group = 'default',
anchorX = 0.5,
anchorY = 1,
vflip = false,
hflip = false,
tint = { r = 255, g = 255, b = 255, a = 255 },
sx = 1,
sy = 1
}, e.draw)
end
function drawSystem:process(entity, dt)
if entity.draw.onDraw then
entity.draw.onDraw(entity)
end
if config.debug and entity.body then
physicsSystem:debugDraw(entity)
end
end
return drawSystem
end
return drawSystem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment