Re: Hardon Collider not detecting collision
Posted: Mon Jun 11, 2012 3:19 pm
Yeah, it works for me too, now even stranger :S I'm really confused, what a mystery.
Code: Select all
main.lua:72: attempt to call method 'iterate' (a nil value)
I forgot .tileData.Kadoba wrote:map[1].tl["ground"].tileData.iterate() works for me. Can you upload another .love?
Code: Select all
ERROR: AdvTiledLoader/Grid.lua:57: attempt to index local 'self' (a nil value)
Code: Select all
function get_solid_tiles(map)
local collidable_tiles = {}
local layer = map.tl["ground"]
for tileX, tileY, tile in layer.tileData.iterate() do
if tile and tile.properties.solid then
local ctile = collider:addRectangle((tileX - 1) * 16, (tileY - 1) * 16, 16, 16)
ctile.type = "tile"
collider:addToGroup("tiles", ctile)
collider:setPassive(ctile)
table.insert(collidable_tiles, ctile)
end
end
print(#collidable_tiles)
end
Code: Select all
function get_solid_tiles(map)
local collidable_tiles = {}
local layer = map.tl["ground"]
for tileX, tileY, tile in layer.tileData:iterate() do
if tile and tile.properties.solid then
local ctile = collider:addRectangle((tileX - 1) * 16, (tileY - 1) * 16, 16, 16)
ctile.type = "tile"
collider:addToGroup("tiles", ctile)
collider:setPassive(ctile)
table.insert(collidable_tiles, ctile)
end
end
print(#collidable_tiles)
end
Thank you, that fixed it However, "if tile and tile.properties.solid then" is never being called.Kadoba wrote:Iterate needs to be called using a colon instead of a period.
Code: Select all
function get_solid_tiles(map) local collidable_tiles = {} local layer = map.tl["ground"] for tileX, tileY, tile in layer.tileData:iterate() do if tile and tile.properties.solid then local ctile = collider:addRectangle((tileX - 1) * 16, (tileY - 1) * 16, 16, 16) ctile.type = "tile" collider:addToGroup("tiles", ctile) collider:setPassive(ctile) table.insert(collidable_tiles, ctile) end end print(#collidable_tiles) end
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="26" height="24" tilewidth="25" tileheight="25">
<tileset firstgid="1" name="Tiles" tilewidth="25" tileheight="25">
<properties>
<property name="solid" value="1"/>
</properties>
<image source="tileset.png" width="50" height="50"/>
</tileset>
<layer name="ground" width="26" height="24">
<properties>
<property name="ground" value="1"/>
</properties>
<data encoding="base64" compression="zlib">
eJxjYWBgYKETJgYQqw6X3pFqDyWAWnFHrD20BoPZHnroITfuBqM9LEg0rcKNBY0mFRCyB11+qNuDTf1wsodcMGrPqD3I9tADAwBmFgIF
</data>
</layer>
</map>
Ah, I get it. I managed to make it work. I'll just use "layer.properties.solid", instead of setting each tile to "solid".Kadoba wrote:You had the solid property in your layer set to 1, but not in the individual tiles.