Box2D Forums

It is currently Sat May 18, 2013 5:51 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Dec 20, 2010 3:01 pm 
Offline

Joined: Tue Dec 14, 2010 10:38 am
Posts: 18
I'm attempting to change the 'active' setting of a dynamically created BodyShape upon a beginContactEvent involving one of its peers within the same MovieClip.

(I only mention that it's dynamically created because I've had no trouble changing attributes on BodyShapes that are not.)

I'm detecting contact between object1 & object 2 successfully, but I've been unable to find the right syntax for setting object3's 'active' value.

Here's one of many failed attempts:

Code:
      private function handleContact(e:ContactEvent):void
      {
         if (e.other.m_userData.name == "object1" && e.fixture.m_userData.name == "object2")
         {
            var theMutualParent = MovieClip(MovieClip(e.fixture.m_userData).parent);
            LineArc90(theMutualParent.object3).active = true;
         }
      }


When contact occurs I get the following error: "Assertion failed: (m_world->IsLocked() == false), function SetActive, file ../Box2D/Dynamics/b2Body.cpp, line 426."

I appreciate any insight! Thanks!


Top
 Profile  
 
PostPosted: Mon Dec 20, 2010 4:30 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
Box2D doesn't like you to do certain things while inside the timestep. Try this instead:

Code:
world.doOutsideTimeStep(function() {
    (e.relatedObject as DisplayObject).parent as BodyShape).active = true;
});


Top
 Profile  
 
PostPosted: Tue Dec 21, 2010 9:53 am 
Offline

Joined: Tue Dec 14, 2010 10:38 am
Posts: 18
Perfect! 'doOutsideTimeStep' is just what I needed! Here's what I ended up doing (for anyone who might need this in the future):

Code:

private function handleContact(e:ContactEvent):void
{
   if (e.other.m_userData.name == "object1" && e.fixture.m_userData.name == "object2")
   {
      var theMutualParent = (e.fixture.m_userData as DisplayObject).parent;
      world.doOutsideTimeStep( function() {
         (theMutualParent.getChildByName('object3') as BodyShape).active = true;
      });
   }
}



Thank you for your help!


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