Using the world callback?

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.
Post Reply
User avatar
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

Using the world callback?

Post 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
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Using the world callback?

Post 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.
User avatar
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

Re: Using the world callback?

Post 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
User avatar
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

Re: Using the world callback?

Post by conman420 »

Also is there a way of retrieving if any key is being pressed?
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Using the world callback?

Post by rude »

Of course. love.keyboard.isDown. See constants for key symbols.
User avatar
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

Re: Using the world callback?

Post 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.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Using the world callback?

Post 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
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: Using the world callback?

Post by Merkoth »

Correctme if I'm wrong, but wouldn't the keypressed() and keyreleased() callbacks do the trick too?
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Using the world callback?

Post by rude »

I think he wants to know if any key is down at any time.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 61 guests