I followed the example code very closely, and the lights work my map at a scaling of 1 (e.g. no scaling at all), but when I try to scale the map up to 2, the light appears offset improperly with the map. This is my `main.lua` code:
Code: Select all
local Camera = require("lib.camera")
local map = require("scripts.map")
local LightWorld = require("lib.lightworld")
function love.load()
love.graphics.setBackgroundColor(love.math.colorFromBytes(41, 45, 65))
love.physics.setMeter(64)
world = love.physics.newWorld(0, 9.81*64, true)
windowWidth = love.graphics.getWidth()
windowHeight = love.graphics.getHeight()
lightWorld = LightWorld({
ambient = {0.21, 0.21, 0.21},
})
lightMouse = lightWorld:newLight(0, 0, 1, 0.49, 0.24, 300)
lightMouse:setGlowStrength(0.3)
map:load()
end
function love.update(dt)
if love.keyboard.isDown('escape') then love.event.quit() end
lightWorld:update(dt)
lightWorld:setTranslation(0, 0, map.scale)
lightMouse:setPosition(love.mouse.getX(), love.mouse.getY())
end
function love.draw()
love.graphics.push()
love.graphics.scale(map.scale)
lightWorld:draw(function()
map:draw()
end)
love.graphics.pop()
end
Code: Select all
local sti = require("lib.sti")
local map = {
scale = 2
}
function map:load()
self.map = sti("maps/testmap.lua")
self.width = self.map.width * self.map.tilewidth * self.scale
self.height = self.map.height * self.map.tileheight * self.scale
local solidColliders = {}
for i, obj in pairs(self.map.layers["Solids"].objects) do
solidColliders.body = love.physics.newBody(world, (obj.x + obj.width/2) * self.scale, (obj.y + obj.height/2) * self.scale, "static")
solidColliders.shape = love.physics.newRectangleShape(obj.width * self.scale, obj.height * self.scale)
solidColliders.fixture = love.physics.newFixture(solidColliders.body, solidColliders.shape)
solidColliders.fixture:setUserData("Solids")
lightWorld:newRectangle((obj.x + obj.width/2) * self.scale, (obj.y + obj.height/2) * self.scale, obj.width * self.scale, obj.height * self.scale)
end
end
function map:draw()
self.map:drawImageLayer("Map")
end
return map
Here is the full source and `.love` file that you can try out (scaling is set to 2)