diff options
Diffstat (limited to 'Transform.lua')
-rw-r--r-- | Transform.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Transform.lua b/Transform.lua new file mode 100644 index 0000000..0038cce --- /dev/null +++ b/Transform.lua @@ -0,0 +1,28 @@ +local component = require 'component' + +-- component for objects that have a position in the world +local Transform = component() +function Transform:init(inst) + inst.pos = inst.pos or {0, 0} + inst.angle = inst.angle or 0 + inst.scale = inst.scale or {1, 1} + if type(inst.scale) == 'number' then + inst.scale = {inst.scale, inst.scale} + end +end + +function Transform:love(trans) + local trans = trans or love.math.newTransform() + local x, y = unpack(self.i.pos) + local sx, sy = unpack(self.i.scale) + trans:setTransformation(x, y, self.i.angle, sx, sy) + return trans +end + +local trans = love.math.newTransform() +function Transform:use() + self:love(trans) -- this is literally me + love.graphics.applyTransform(trans) +end + +return Transform |