From 048dc835d941b4f8b3f660e7e6baf3733e2a69f6 Mon Sep 17 00:00:00 2001 From: Paul Liverman Date: Sun, 26 Oct 2014 12:37:18 -0700 Subject: [PATCH] shadow work around complete --- src/lightWorldRectangleFix.lua | 18 ++++++++++++++++++ src/main.lua | 34 ++++------------------------------ 2 files changed, 22 insertions(+), 30 deletions(-) create mode 100644 src/lightWorldRectangleFix.lua diff --git a/src/lightWorldRectangleFix.lua b/src/lightWorldRectangleFix.lua new file mode 100644 index 0000000..888d390 --- /dev/null +++ b/src/lightWorldRectangleFix.lua @@ -0,0 +1,18 @@ +function lightWorldRectangleFix(world, x, y, w, h) + -- add half of width/height because lightWorld uses centered rectangles + local shadow = world:newRectangle(x + w / 2, y + h / 2, w, h) + -- fix ox/oy, width, height + shadow.ox = w / 2 + shadow.oy = h / 2 + shadow.width = w + shadow.height = h + -- fix data object + shadow.data = { + --4 pairs x/y, clockwise + x, y, + x + w, y, + x + w, y + h, + x, y + h + } + return shadow +end diff --git a/src/main.lua b/src/main.lua index 2c817da..2c89070 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,4 +1,6 @@ function love.load() + require "lightWorldRectangleFix" + local LightWorld = require "lib.light_world" lightWorld = LightWorld({ drawBackground = drawBackground, @@ -12,40 +14,12 @@ function love.load() thompson = { color = {255, 0, 0}, - --[[x = 50, + x = 50, y = 50, w = 17, - h = 27]] - x = 500, - y = 50, - w = 170, h = 27 } - thompson.shadow = lightWorld:newRectangle(thompson.x + thompson.w / 2, thompson.y + thompson.h / 2, thompson.w, thompson.h) - -- work arounds for broken constructor - thompson.shadow.ox = thompson.w / 2--* 2--/ 2 - thompson.shadow.oy = thompson.h / 2--* 2--/ 2 - thompson.shadow.width = thompson.w - thompson.shadow.height = thompson.h - thompson.shadow.data = { - --8 values, 4 x/y pairs, start at top left, clockwise - thompson.x, - thompson.y, - thompson.x + thompson.w, - thompson.y, - thompson.x + thompson.w, - thompson.y + thompson.h, - thompson.x, - thompson.y + thompson.h - } - - -- temp logging for attempt to resolve issues - for k,v in pairs(thompson.shadow) do - print(k.."="..tostring(v)) - end - for k,v in pairs(thompson.shadow.data) do - print(k.."="..tostring(v)) - end + thompson.shadow = lightWorldRectangleFix(lightWorld, thompson.x, thompson.y, thompson.w, thompson.h) end function love.update(dt)