Skip to content

Instantly share code, notes, and snippets.

@Bradshaw
Last active January 22, 2018 20:31
Show Gist options
  • Save Bradshaw/a3744d7e40e90fb4e7df to your computer and use it in GitHub Desktop.
Save Bradshaw/a3744d7e40e90fb4e7df to your computer and use it in GitHub Desktop.
The magic of ellipsis in Lua
local old_draw = love.graphics.draw
local monkey_draw = function(im, ...)
if fudge.current and type(im)=="string" then
--Get associate and draw it
local fud = fudge.current:getPiece(im)
old_draw(fud.img, fud.quad, ...)
elseif type(im)=="table" and im.img and im.quad then
old_draw(im.img, im.quad, ...)
elseif type(im)=="table" and im.batch then
old_draw(im.batch)
else
old_draw(im, ...)
end
end
-- Call like -> a:draw(subimage, x, y, angle, scalex, scaley, ox, oy)
function Animation:draw(subimage, ...)
if subimage then
subimage = math.min(self.n_frames, math.floor(subimage))
else
subimage = 1
end
love.graphics.draw(self.img, self.quads[subimage], ...) -- Lua is magic n.n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment