[SOLVED] Two Rectangles, One Physics Body how?

  ... the Physics Box2D Extension for AndEngine.

[SOLVED] Two Rectangles, One Physics Body how?

Postby kentsusai » Sat Feb 25, 2012 4:00 am

Hi all,

I've searched the forums and I haven't had much luck.

I have created two Rectangle objects. I want both of those Rectangles to maintain a particular displacement. For example, Rectangle rect1 is at co-ordinates X,Y and Rectangle rect2 is at co-ordinates X,Y+1.

I want both of these Rectangles to fall and collide together.

I have tried attaching them as child objects to an Entity object but you can't use the PhysicsFactory.createBoxBody with Entity objects.

I'm sure someone has done this before. Any idea?

Thanks! :D
Last edited by kentsusai on Sat Feb 25, 2012 11:05 am, edited 1 time in total.
kentsusai
 
Posts: 6
Joined: Sat Feb 25, 2012 3:25 am


Re: Two Rectangles, One Physics Body how?

Postby kentsusai » Sat Feb 25, 2012 9:55 am

Is there a working example of this anywhere?

BTW, are you sure you can register a Rectangle object or an Entity object using PhysicsConnector?
kentsusai
 
Posts: 6
Joined: Sat Feb 25, 2012 3:25 am

Re: Two Rectangles, One Physics Body how?

Postby kentsusai » Sat Feb 25, 2012 11:05 am

Came up with a work around

Make a Rectangle object to act as the parent.

Add other Rectangle objects as children of parent Rectangle object.

Make a Body object using CreateBoxBody using the width and height of the Rectangles combined.

Use PhysicsConnector to register the parent Rectangle object with the Body object.
kentsusai
 
Posts: 6
Joined: Sat Feb 25, 2012 3:25 am


Return to Physics Box2D

Who is online

Users browsing this forum: kadamdeepak and 7 guests