From 600d02ca63d3893729fb60549fecd34d62d50587 Mon Sep 17 00:00:00 2001 From: "jiangzhi.xie" Date: Sun, 8 Sep 2019 12:53:47 +0800 Subject: [PATCH] Fix body shadow --- lib/body.lua | 14 +++++--------- lib/init.lua | 5 +++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/body.lua b/lib/body.lua index c35d806..d3a3bb8 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -382,10 +382,6 @@ end -- set glass color function body:setColor(r, g, b) - if r > 1 then r = r / 255 end - if g > 1 then g = r / 255 end - if b > 1 then b = r / 255 end - self.red = r self.green = g self.blue = b @@ -689,7 +685,7 @@ function body:drawShadow(light) return end - love.graphics.setColor(self.red, self.green, self.blue, self.alpha) + love.graphics.setColor(self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255) if self.shadowType == "polygon" then self:drawPolyShadow(light) elseif self.shadowType == "circle" then @@ -779,10 +775,10 @@ function body:drawImageShadow(light) local shadowY = (length * math.cos(shadowRotation) + 1.0) * shadowStartY self.shadowMesh:setVertices({ - {shadowX, shadowY, 0, 0, self.red, self.green, self.blue, self.alpha}, - {shadowX + self.imgWidth, shadowY, 1, 0, self.red, self.green, self.blue, self.alpha}, - {self.imgWidth, shadowStartY, 1, 1, self.red, self.green, self.blue, self.alpha}, - {0, shadowStartY, 0, 1, self.red, self.green, self.blue, self.alpha} + {shadowX, shadowY, 0, 0, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255}, + {shadowX + self.imgWidth, shadowY, 1, 0, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255}, + {self.imgWidth, shadowStartY, 1, 1, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255}, + {0, shadowStartY, 0, 1, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255} }) love.graphics.draw(self.shadowMesh, self.x, self.y, self.rotation, self.scalex, self.scaley, self.ox, self.oy) diff --git a/lib/init.lua b/lib/init.lua index cf58879..e6beea0 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -104,7 +104,6 @@ function light_world:draw(cb) _ = self.disableReflection or self:drawReflection( self.l,self.t,self.w,self.h,self.s) end) self.post_shader:drawWith(self.render_buffer, self.l, self.t, self.s) - -- love.graphics.draw(self.shadow_buffer) end -- draw normal shading @@ -169,7 +168,9 @@ function light_world:drawShadows(l,t,w,h,s) shader = self.shadowShader, stencil = function() local angle = light.direction - (light.angle / 2.0) - love.graphics.arc("fill", (light.x + l/s) * s, (light.y + t/s) * s, light.range, angle, angle + light.angle) + love.graphics.arc( + "fill", (light.x + l/s) * s, (light.y + t/s) * s, light.range, angle, angle + light.angle + ) end }) end