Hi All, Heres the issue - I extend B2ContactListener so I can change the UserData on objects that have collisions. I create my custom contact listener class and use the SetContactListener( ) function to apply it to the world. However, it soon became clear that I wasn't getting any contacts so.... I trace back to the b2World class where the BeginContact function is being called and it seems its not getting called there either! As you can see I have traces in all blocks of code and none are getting called. Any help here would be appreciated! Thanks Dan
Heres my code:
//setting up new listener ( from main game class )
var contact_listener : PopoutContactListener = new PopoutContactListener();
_world.SetContactListener( contact_listener ) ;
// overrides begincontact (copied from PopoutContactListener that extends b2ContactListener )
override public function BeginContact(contact:b2Contact):void {
trace('BeginContact call ') ;
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
var data : Object ;
if (fixtureB.IsSensor()) {
data = getUserData( fixtureB.GetBody() ) ;
data.status = 'hit'
fixtureB.GetBody().SetUserData( 'hit' );
}
if (fixtureA.IsSensor()) {
data = getUserData( fixtureA.GetBody() ) ;
data.status = 'hit'
fixtureA.GetBody().SetUserData( 'hit' );
}
}
protected function getUserData( body : b2Body ) : Object
{
trace('getUserData call ', body ) ;
return body.GetUserData() ;
}
// from the b2World class
public function BeginContact(c:int, a:b2Fixture, b:b2Fixture):void {
trace('begin contact');
if(m_contactListener){
m_contactListener.BeginContact(new b2Contact(c, a, b));
}
}
Heres my code:
//setting up new listener ( from main game class )
var contact_listener : PopoutContactListener = new PopoutContactListener();
_world.SetContactListener( contact_listener ) ;
// overrides begincontact (copied from PopoutContactListener that extends b2ContactListener )
override public function BeginContact(contact:b2Contact):void {
trace('BeginContact call ') ;
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
var data : Object ;
if (fixtureB.IsSensor()) {
data = getUserData( fixtureB.GetBody() ) ;
data.status = 'hit'
fixtureB.GetBody().SetUserData( 'hit' );
}
if (fixtureA.IsSensor()) {
data = getUserData( fixtureA.GetBody() ) ;
data.status = 'hit'
fixtureA.GetBody().SetUserData( 'hit' );
}
}
protected function getUserData( body : b2Body ) : Object
{
trace('getUserData call ', body ) ;
return body.GetUserData() ;
}
// from the b2World class
public function BeginContact(c:int, a:b2Fixture, b:b2Fixture):void {
trace('begin contact');
if(m_contactListener){
m_contactListener.BeginContact(new b2Contact(c, a, b));
}
}