Page 1 of 1
world callbacks problem
Posted: Wed Aug 25, 2010 12:47 pm
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?
Re: world callbacks problem
Posted: Wed Aug 25, 2010 7:20 pm
by Robin
Please rephrase your question so us mortals can understand.
Re: world callbacks problem
Posted: Thu Aug 26, 2010 4:54 am
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?
Re: world callbacks problem
Posted: Wed Sep 15, 2010 10:49 am
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.
Re: world callbacks problem
Posted: Wed Sep 15, 2010 6:12 pm
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.)
Re: world callbacks problem
Posted: Wed Sep 15, 2010 6:56 pm
by bartbes
The result callback, as far as I can tell, is called after a contact has been 'resolved'.