Setting a Windfield collision type for colliders generated from a table
Posted: Mon Oct 11, 2021 2:58 am
Hi, I'm currently learning love2D by experimenting with making some simple versions of a few different 2D games and after learning some basics over the past week or so I'm starting with a sidescrolling platformer.
I'm using Tiled to create my maps, and Windfield for my physics and collisions. After a bit of work I was able to find and mostly understand some code that converts one of my Tiled map layers into Windfield colliders by creating a table with the location of the solid tiles and generating rectangle colliders the same size as those tiles in those locations.
However, I say I mostly understand it because the problem I'm running into is actually setting the type of these colliders to be 'static'. I know normally you'd use :setType('static') but currently I'm not sure which variable I need to actually set to static, or where in the loop to do it.
Here's the code that I'm using:
This works exactly how I need it to in terms of scanning my maps and generating colliders in the correct positions but I have absolutely no idea which variable to change, and where, to make these colliders 'static'. I also imagine this could probably be done much more cleanly but I'm not entirely sure how.
If anyone could explain what I'm missing that would be greatly appreciated!
EDIT: Sorry for bumping, attaching the .love
I'm wondering if what I'm trying to do is even possible? Would I be better off just not using Windfield?
I'm using Tiled to create my maps, and Windfield for my physics and collisions. After a bit of work I was able to find and mostly understand some code that converts one of my Tiled map layers into Windfield colliders by creating a table with the location of the solid tiles and generating rectangle colliders the same size as those tiles in those locations.
However, I say I mostly understand it because the problem I'm running into is actually setting the type of these colliders to be 'static'. I know normally you'd use :setType('static') but currently I'm not sure which variable I need to actually set to static, or where in the loop to do it.
Here's the code that I'm using:
Code: Select all
function love.load()
currentMap = sti('maps/plat_map1.lua')
currentWorld = wf.newWorld()
--searches for the "solids" layer of the map file and then creates collision boxes on top of the tiles
local map = love.filesystem.load('maps/plat_map1.lua')()
local mapW = map.width
local mapH = map.height
local colliderList = {}
local layerNum = 1
local layer = map.layers[layerNum]
while layer do
if layer.name == 'solids' then
local y = 0
while y < mapH do
local x = 0
while x < mapW do
local tileID = (y * mapW) + x + 1
local tile = layer.data[tileID]
if tile > 0 then
table.insert(colliderList, currentWorld:newRectangleCollider(x * 16, y * 16, 16, 16))
end
x = x + 1
end
y = y + 1
end
end
layerNum = layerNum + 1
layer = map.layers[layerNum]
end
end
function love.update(dt)
currentWorld:update(dt)
end
function love.draw()
currentMap:drawLayer(currentMap.layers["background"])
love.graphics.push()
love.graphics.setColor(1, 0, 0)
currentWorld:draw()
love.graphics.pop()
end
If anyone could explain what I'm missing that would be greatly appreciated!
EDIT: Sorry for bumping, attaching the .love
I'm wondering if what I'm trying to do is even possible? Would I be better off just not using Windfield?