Oh, I don't noticed that, Karai. I was looking for the size somewhere with collision map type, orientation, collision and so.Karai17 wrote:You should be able to access map.tilewidth and map.tileheight without any problem.
That's what I will do, but I'm really thinking about use love.physics. And keep it apart from STI to keep things easy to update.Cerulean Knight wrote:If you are using HardonCollider, you can add a few lines in the Map:getCollisionMap function.ochetski wrote:I asked because I did implemented a collision system with STI. But needed to set the tile sizes hard coded, because I wasn't able to get tiles width and height from the map.
My collision system is now ugly, complex and hard to use with multiple entities. I will probably change it to use love.physics. I will share it here as soon as I finish it.
Thanks Karai, please keep the good work because it will bring great games to life.
So, the final result is this (if you are using 32x32 tiles):
Then, when you load a collision map, HC will create all invisible square on the map positions.Code: Select all
function Map:getCollisionMap(index) local layer = assert(self.layers[index], "Layer not found: " .. index) assert(layer.type == "tilelayer", "Invalid layer type: " .. layer.type .. ". Layer must be of type: tilelayer") local w = self.width local h = self.height local map = { type = layer.type, orientation = layer.orientation, collision = true, opacity = 0.5, data = {}, } for y=1, h do map.data[y] = {} for x=1, w do if layer.data[y][x] == nil then map.data[y][x] = 0 else map.data[y][x] = 1 ctile = collider:addRectangle((x-1)*32, (y-1)*32, 32, 32) collider:setPassive(ctile) end end end return map end
Note: collider is the variable that you define beforeCode: Select all
collider = HC(100, on_collision,stop_collision)
Thanks!