world callbacks problem

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
SobaK
Prole
Posts: 2
Joined: Wed Aug 25, 2010 12:33 pm

world callbacks problem

Post by SobaK »

When one shape is sensor and another shape inside this sensor-shape engine calls "add" callback several times... And it is not good, so i need this callback only once - when two shapes collided. Anyone had same problem? And how I can solve it?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: world callbacks problem

Post by Robin »

Please rephrase your question so us mortals can understand. :P
Help us help you: attach a .love.
SobaK
Prole
Posts: 2
Joined: Wed Aug 25, 2010 12:33 pm

Re: world callbacks problem

Post by SobaK »

Ok, I'll try=)
For example I have 2 shapes, and

shape1:isSensor() = true
shape2:isSensor() = false

Also I set world callbacks like

myWorld:setCallbacks(addCallback, nil, nil, nil)

In game i have situation when second shape moves through first shape.In this situation addCallback called several times while shapes in contact.
But it should be called only once, as i understand from wiki... It is bug or feature?=) Or others don't have this bug, and probably problem in my code?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: world callbacks problem

Post by kikito »

I think it is a feature.

I don't have the time to do the tests now, but placing the callback on one of the nils (I don't remember which one) should do the trick - probably the second, like this:

Code: Select all

myWorld:setCallbacks(nil, yourCallback, nil, nil)
One of the callbacks runs "every frame the bodies touch".
One of the callbacks runs once, in "the first frame the bodies touch".
The other runs once, in "just after the last frame the bodies touch".
There was also one misterous callback that I never understood when it was called.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: world callbacks problem

Post by Robin »

kikito wrote:There was also one misterous callback that I never understood when it was called.
It truly is a mystery to all. Really! I'd give you money if you could tell me what it does exactly, if bartbes'd give me his bank card. (Got his PIN already.)
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: world callbacks problem

Post by bartbes »

The result callback, as far as I can tell, is called after a contact has been 'resolved'.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 56 guests