blob: 0038cce29f81df73b10efcfb2d8a5bdd8e8af6f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
|