Hardon Collider not detecting collision

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Hardon Collider not detecting collision

Post by munchor »

Yeah, it works for me too, now even stranger :S I'm really confused, what a mystery.
Attachments
stack-tile.love
(61.15 KiB) Downloaded 139 times
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Hardon Collider not detecting collision

Post by Kadoba »

maps[1].tl["ground"] isn't nil for me. How are you testing it?
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Hardon Collider not detecting collision

Post by munchor »

Neither to me, but I get this:

Code: Select all

main.lua:72: attempt to call method 'iterate' (a nil value)
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Hardon Collider not detecting collision

Post by Kadoba »

map[1].tl["ground"].tileData.iterate is there for me. Can you upload another .love?
Last edited by Kadoba on Tue Jun 12, 2012 3:46 pm, edited 1 time in total.
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Hardon Collider not detecting collision

Post by munchor »

Kadoba wrote:map[1].tl["ground"].tileData.iterate() works for me. Can you upload another .love?
I forgot .tileData.

Attached is a .love.

Code: Select all

ERROR: AdvTiledLoader/Grid.lua:57: attempt to index local 'self' (a nil value)
I'm getting that error, and it is being reported somewhere in this function:

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
Thanks in advance!
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Hardon Collider not detecting collision

Post by Kadoba »

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
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Hardon Collider not detecting collision

Post by munchor »

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
Thank you, that fixed it :) However, "if tile and tile.properties.solid then" is never being called.

By this I mean, tile.properties.solid is always "nil". I am sure I have a tileset of tiles with the property "solid" set to "1".

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>
There's .tmx file, attached is yet another .love.
Attachments
stack-tile.love
(61.16 KiB) Downloaded 127 times
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Hardon Collider not detecting collision

Post by Kadoba »

You had the solid property in your layer set to 1, but not in the individual tiles.
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Hardon Collider not detecting collision

Post by munchor »

Kadoba wrote:You had the solid property in your layer set to 1, but not in the individual tiles.
Ah, I get it. I managed to make it work. I'll just use "layer.properties.solid", instead of setting each tile to "solid".

Thank you tons for the help!
paclito
Prole
Posts: 35
Joined: Wed Apr 22, 2009 8:33 pm

Re: Hardon Collider not detecting collision

Post by paclito »

I'm trying to get working this example but :) I'm not capable to get the player collide with the map. Can someone put a .love where we can see the player colliding with the map?

aaand

jejeje how can i get the point where the collide or collision is done... perhaps to put a flame on the correct side or some sparks ? crash!

sorry for my poor english
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests