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 » Mon Jun 11, 2012 3:19 pm

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 68 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 » Mon Jun 11, 2012 3:51 pm

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 » Mon Jun 11, 2012 4:30 pm

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 » Tue Jun 12, 2012 2:34 pm

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 » Tue Jun 12, 2012 3:20 pm

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 » Tue Jun 12, 2012 3:51 pm

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 » Tue Jun 12, 2012 3:59 pm

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 72 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 » Tue Jun 12, 2012 4:19 pm

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 » Tue Jun 12, 2012 4:26 pm

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 » Fri Aug 31, 2012 10:27 pm

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: Bing [Bot], Google [Bot] and 7 guests