From b0a904cd4982102bde77ba6a819274d84a604f9c Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 20 Feb 2025 16:52:10 +0800 Subject: refactor: draw sprite according to body --- objects/Body.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'objects/Body.lua') diff --git a/objects/Body.lua b/objects/Body.lua index 72dbbe5..aa5bd75 100644 --- a/objects/Body.lua +++ b/objects/Body.lua @@ -40,10 +40,18 @@ end function Body:draw(x, y) if self.shape == "circle" then - -- 绘制圆形 love.graphics.circle("fill", x, y, self.r) elseif self.shape == "rectangle" then - -- 绘制矩形 love.graphics.rectangle("fill", x - self.w / 2, y - self.h / 2, self.w, self.h) end end + +function Body:drawSprite(spriteName, x, y, angle) + local sprite = sprites[spriteName] + local w, h = (self.shape == "circle" and self.r or self.w), (self.shape == "circle" and self.r or self.h) + + love.graphics.draw(sprite, x, y, angle, + w / sprite:getWidth(), + h / sprite:getHeight() + ) +end -- cgit v1.2.3