From ccf1621123e3596666b5d7c00ba5a9b339b16aa9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 18 Mar 2019 17:28:43 +0100 Subject: [PATCH] modules/assets: make animation support mask Fix #4 --- examples/test_scene2/init.lua | 1 + gamecore/modules/assets/animator.lua | 4 ++++ gamecore/modules/assets/sprites.lua | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/examples/test_scene2/init.lua b/examples/test_scene2/init.lua index 588d5ac..4f08301 100644 --- a/examples/test_scene2/init.lua +++ b/examples/test_scene2/init.lua @@ -65,6 +65,7 @@ function TestScene:draw() love.graphics.setColor(0, 1, 0, 1) self.assets.images["debris"]:drawMask(16, 32) self.assets.tileset["weapon"]:drawTileMask(3, 32, 32) + self.assets.sprites["poof"]:drawAnimationMask(64, 32) utils.graphics.resetColor() end diff --git a/gamecore/modules/assets/animator.lua b/gamecore/modules/assets/animator.lua index 7bce90c..716263c 100644 --- a/gamecore/modules/assets/animator.lua +++ b/gamecore/modules/assets/animator.lua @@ -77,6 +77,10 @@ function Animator:draw(x, y, r, sx, sy, ox, oy, kx, ky) self.sprite:drawFrame(self.frame, x, y, r, sx, sy, ox, oy, kx, ky) end +function Animator:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) + self.sprite:drawFrameMask(self.frame, x, y, r, sx, sy, ox, oy, kx, ky) +end + function Animator:changeAnimation(name, restart) -- Force restart if animation name is different if (self.currentAnimation ~= name) then diff --git a/gamecore/modules/assets/sprites.lua b/gamecore/modules/assets/sprites.lua index 032f147..0749b63 100644 --- a/gamecore/modules/assets/sprites.lua +++ b/gamecore/modules/assets/sprites.lua @@ -68,10 +68,18 @@ function Sprite:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky) self.animator:draw(x, y, r, sx, sy, ox, oy, kx, ky) end +function Sprite:drawAnimationMask(x, y, r, sx, sy, ox, oy, kx, ky) + self.animator:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) +end + function Sprite:drawFrame(frame, x, y, r, sx, sy, ox, oy, kx, ky) self.tileset:drawTile(frame, x, y, r, sx, sy, ox, oy, kx, ky) end +function Sprite:drawFrameMask(frame, x, y, r, sx, sy, ox, oy, kx, ky) + self.tileset:drawTileMask(frame, x, y, r, sx, sy, ox, oy, kx, ky) +end + function Sprite:drawPart(x, y, w, h, r, sx, sy, ox, oy, kx, ky) local w = math.floor(w) local h = math.floor(h)