Box2D Forums

It is currently Sun May 19, 2013 8:50 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Sep 04, 2012 3:51 am 
Offline

Joined: Fri Nov 05, 2010 4:24 am
Posts: 9
Hi guys,

i'm moving a Dynamic body (call it earth) with my arrow keys, and i need to move another body - lets call this one a moon (one without collision - it's representing a gfx sprite for the final version in my testbed) around the earth(calculating the position is not the problem)

so how can i update the position for the moon, when earth changes its position?

thanks in advance!


Top
 Profile  
 
PostPosted: Tue Sep 04, 2012 4:33 am 
Offline

Joined: Fri Nov 05, 2010 4:24 am
Posts: 9
finally resolved!

Code:

      Body body = earth;
      World world = body.getWorld();

      CircleShapeBuilder csb = new CircleShapeBuilder(world);
      csb.type(BodyType.DYNAMIC);
      csb.radius(1f);
      csb.position((float) (body.getPosition().x),
            (float) (body.getPosition().y + offset));
      csb.angularDamping(0f);
      csb.userData(this);
      moon = csb.build();

      RevoluteJointDef jointDef = new RevoluteJointDef();
      jointDef.initialize(body, moon, body.getWorldCenter());
      world.createJoint(jointDef);


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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