summaryrefslogtreecommitdiff
path: root/tilemap.lua
diff options
context:
space:
mode:
authorcursed22bc <admin@pixeldawn.org>2026-03-01 11:17:23 +0200
committercursed22bc <admin@pixeldawn.org>2026-03-01 11:17:23 +0200
commit8f9182baff36d33c07c5eb8df795e3cfcd5307a5 (patch)
tree97d66e64e36f447b950609d5e849e24f2c438731 /tilemap.lua
parent6eacf393b370a7586276108705b805e222a069a5 (diff)
improved tileset and load
Diffstat (limited to 'tilemap.lua')
-rw-r--r--tilemap.lua12
1 files changed, 4 insertions, 8 deletions
diff --git a/tilemap.lua b/tilemap.lua
index 64ca520..4780cfe 100644
--- a/tilemap.lua
+++ b/tilemap.lua
@@ -39,7 +39,7 @@ local function objectToEntity(obj)
return entity
end
-function Tilemap:new(map)
+function Tilemap:new(mapPath, tilesetPath)
local self = setmetatable({}, Tilemap)
self.entitiesTiles = {}
@@ -55,7 +55,7 @@ function Tilemap:new(map)
self.tilesetImage = nil
self.tileQuads = {}
- local mapData = loadMapData(map)
+ local mapData = loadMapData(mapPath)
self.mapData = mapData
self.tileWidth = mapData and (mapData.tilewidth or 16) or 16
@@ -63,10 +63,8 @@ function Tilemap:new(map)
self.mapWidth = (mapData and mapData.width or 0) * self.tileWidth
self.mapHeight = (mapData and mapData.height or 0) * self.tileHeight
- if type(map) == "string" then
- local basePath = map:gsub("%.lua$", ""):gsub("%.tmx$", "")
- local imagePath = basePath .. ".png"
- local ok, img = pcall(love.graphics.newImage, imagePath)
+ if type(tilesetPath) == "string" and tilesetPath ~= "" then
+ local ok, img = pcall(love.graphics.newImage, tilesetPath)
if ok and img then
self.tilesetImage = img
local firstGid = (mapData.tilesets and mapData.tilesets[1] and mapData.tilesets[1].firstgid) or 1
@@ -121,8 +119,6 @@ function Tilemap:getEntitiesCameraBorders()
return self.entitiesCameraBorders
end
--- Returns minX, maxX, minY, maxY from camera_border entities for use with Camera:setLimits.
--- Returns nil, nil, nil, nil if there are no camera border entities.
function Tilemap:getCameraLimits()
local borders = self.entitiesCameraBorders
if not borders or #borders == 0 then