local mapWidthLimit = map.width * map.tilewidth - love.graphics.getWidth()
local mapHeightLimit = map.height * map.tileheight - love.graphics.getHeight()
if x > mapWidthLimit then x = mapWidthLimit end
if y > mapHeightLimit then y = mapHeightLimit end
if x < 0 then x = 0 end
if y < 0 then y = 0 end
local mapWidthLimit = (map.width * map.tilewidth) - love.graphics.getWidth()
local mapHeightLimit = (map.height * map.tileheight) - love.graphics.getHeight()
if x < 0 then
x = 0
elseif x > mapWidthLimit then
x = mapWidthLimit
end
if y < 0 then
y = 0
elseif y > mapHeightLimit then
y = mapHeightLimit
end
local mapWidthLimit = map.width * map.tilewidth - love.graphics.getWidth()
local mapHeightLimit = map.height * map.tileheight - love.graphics.getHeight()
x = x < 0 and 0 or x > mapWidthLimit and mapWidthLimit or x
y = y < 0 and 0 or y > mapHeightLimit and mapHeightLimit or y
local mw = map.width - love.graphics.getWidth()
local mh = map.height - love.graphics.getHeight()
if x >= mw then x = mw end
if y >= mh then y = mh end
if x <= 0 then x == 0 end
if y <= 0 then y == 0 end
The code itself isn't much different to what you posted.
I had this placed in the desert examples update function.