Properly resetting PhysicsWorld

  ... the Physics Box2D Extension for AndEngine.

Properly resetting PhysicsWorld

Postby skyuzo » Sat Oct 22, 2011 1:36 pm

Am I doing it right?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void resetPhysics() {
  2.         mPhysicsWorld.getPhysicsConnectorManager().clear();
  3.        
  4.         Iterator<Joint> joints = mPhysicsWorld.getJoints();
  5.         while (joints.hasNext()) {
  6.             Joint j = joints.next();
  7.             if (j != null) mPhysicsWorld.destroyJoint(j);
  8.         }
  9.  
  10.         Iterator<Body> bodies = mPhysicsWorld.getBodies();
  11.         while (bodies.hasNext()) {
  12.             Body b = bodies.next();
  13.             if (b != null) mPhysicsWorld.destroyBody(b);
  14.         }
  15.     }
  16.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


EDIT: Also, I'm not sure if I should create a new PhysicsWorld every time I change the level or reset the PhysicsWorld.

EDIT: (I think) I fixed my problem by creating a new PhysicsWorld every time I change the level and calling PhysicsWorld.dispose() by itself (don't need to destroy bodies, etc.) when I no longer needed it.
skyuzo
 
Posts: 76
Joined: Thu Sep 08, 2011 2:29 am

Re: Properly resetting PhysicsWorld

Postby akbrant » Tue Oct 25, 2011 6:34 am

I would like to know this also.
akbrant
 
Posts: 17
Joined: Thu Sep 15, 2011 6:14 am

Re: Properly resetting PhysicsWorld

Postby Mbolland » Tue Nov 08, 2011 12:27 pm

Me too!
Mbolland
 
Posts: 3
Joined: Sun May 08, 2011 11:01 pm

Re: Properly resetting PhysicsWorld

Postby drjava72 » Mon Mar 05, 2012 1:48 pm

yes disposing the world is enough :)
Best Regards,
drJava72
drjava72
 
Posts: 287
Joined: Fri Apr 29, 2011 8:03 am

Re: Properly resetting PhysicsWorld

Postby SaperPL » Thu Jan 31, 2013 8:34 pm

Sorry for grave digging this thread but I'm still not sure how to do this in gles2. When i re-launch my game activity inside same process my sensors in new physicsWorld won't work while collision does. Same goes for standard re-launching the application which i hacked temporarily by killing the process onDestroy;
SaperPL
 
Posts: 52
Joined: Mon Oct 22, 2012 1:50 pm



Return to Physics Box2D

Who is online

Users browsing this forum: No registered users and 9 guests