shadow work around complete

This commit is contained in:
Paul Liverman
2014-10-26 12:37:18 -07:00
parent f94c6fa9f5
commit 048dc835d9
2 changed files with 22 additions and 30 deletions

View File

@@ -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

View File

@@ -1,4 +1,6 @@
function love.load() function love.load()
require "lightWorldRectangleFix"
local LightWorld = require "lib.light_world" local LightWorld = require "lib.light_world"
lightWorld = LightWorld({ lightWorld = LightWorld({
drawBackground = drawBackground, drawBackground = drawBackground,
@@ -12,40 +14,12 @@ function love.load()
thompson = { thompson = {
color = {255, 0, 0}, color = {255, 0, 0},
--[[x = 50, x = 50,
y = 50, y = 50,
w = 17, w = 17,
h = 27]]
x = 500,
y = 50,
w = 170,
h = 27 h = 27
} }
thompson.shadow = lightWorld:newRectangle(thompson.x + thompson.w / 2, thompson.y + thompson.h / 2, thompson.w, thompson.h) thompson.shadow = lightWorldRectangleFix(lightWorld, thompson.x, thompson.y, 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
end end
function love.update(dt) function love.update(dt)