Created
February 22, 2018 15:50
-
-
Save drhayes/745ed3dc110fd8c418348af5c5879a2f to your computer and use it in GitHub Desktop.
An ECS draw system I wrote.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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