Page 1 of 1

Using the world callback?

Posted: Sun Aug 31, 2008 8:49 pm
by conman420
I'm basically trying to get when the players shape collides with another shape, I guess the world collision callback does this but does it take any arguments? I couldn't see them in the documentation if it did and I've tried retrieving them manually, it seems it takes 2 arguments, but I cannot identify what they are.

Any help is appreciated :D

Re: Using the world callback?

Posted: Sun Aug 31, 2008 8:58 pm
by rude
Ah, I've been documenting that today. (Not uploaded yet). I'm sorry the documentation isn't complete.

You basically do this:

Code: Select all

s1 = love.physics.newCircleShape( body1, 20 )
s1:setData("Shape 1")

s2 = love.physics.newCircleShape( body2, 20 )
s2:setData("Shape 2")

world:setCallback(collision)

function collision(a, b, c)
  print(a .. " with " .. b)
end
The first two arguments is whatever data you set with shape:setData. The third is a Contact object with contact point data.

Re: Using the world callback?

Posted: Sun Aug 31, 2008 9:09 pm
by conman420
Ahh no problem :D

Saves me messing with metatables and loops to find out what the args were.

Now I can finally finish my first game :D

Re: Using the world callback?

Posted: Sun Aug 31, 2008 9:18 pm
by conman420
Also is there a way of retrieving if any key is being pressed?

Re: Using the world callback?

Posted: Sun Aug 31, 2008 9:35 pm
by rude
Of course. love.keyboard.isDown. See constants for key symbols.

Re: Using the world callback?

Posted: Sun Aug 31, 2008 9:47 pm
by conman420
You misunderstood - unless I'm missing something - I mean ANY key as in any of them. Of course I could loop through every key in there but that would be tedious.

One last question :D

Is there a velocity limit in the physics engine? My falling boxes of doom seem to not go past a certain speed.

Re: Using the world callback?

Posted: Sun Aug 31, 2008 9:59 pm
by rude
Any key:

Code: Select all

keynum = 0

function keypressed(k)
  keynum = keynum + 1
end

function keyreleased(k)
  keynum = keynum - 1
end

function isAnyKeyDown()
  return keynum > 0
end
conman420 wrote:Is there a velocity limit in the physics engine? My falling boxes of doom seem to not go past a certain speed.
There is no limit that I'm aware of.

EDIT: typo

Re: Using the world callback?

Posted: Mon Sep 01, 2008 2:06 am
by Merkoth
Correctme if I'm wrong, but wouldn't the keypressed() and keyreleased() callbacks do the trick too?

Re: Using the world callback?

Posted: Mon Sep 01, 2008 2:21 am
by rude
I think he wants to know if any key is down at any time.