Box2D Forums

It is currently Sat May 25, 2013 5:53 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: StartContact issue
PostPosted: Mon Aug 15, 2011 8:37 am 
Offline

Joined: Wed Jun 16, 2010 6:52 am
Posts: 8
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));
}
}


Top
 Profile  
 
 Post subject: Re: StartContact issue
PostPosted: Mon Aug 15, 2011 10:46 am 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
You have to set reportBeginContact, reportEndContact, Etc. on the fixtures you want contact events from. This is because there's some overhead when exiting Alchemy and calling the function, so it only does it for fixtures with those flags set.


Top
 Profile  
 
 Post subject: Re: StartContact issue
PostPosted: Thu Aug 18, 2011 5:58 am 
Offline

Joined: Wed Jun 16, 2010 6:52 am
Posts: 8
Thanks very much for this, ill try it at the first oppurtunity! Dan


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group