This project is read-only.

Creating Complex Shapes

Jul 19, 2010 at 10:40 PM
Edited Jul 19, 2010 at 10:43 PM

I am having trouble with this, I could proably make it easy and just create a RevoluteJoint between each point, but I don't think that is the best way to go about it. What i am trying to do is to create a maze. http://www.emanueleferonato.com/2008/12/12/the-magic-of-compound-objects-with-box2d/

 

The problem i am having is how to have the compound shape act as one while rendering it. I know I need one body and multiple fixtures but then how do I draw the Maze boxes?. Each box is 30*30 (.3*.3). I looked at the CompoundShape.cs testbed but it isnt clicking.

 

 

 

private PolygonShape CreateTile(int x,int y)
        {
           
            var bodyShape = new PolygonShape();
            bodyShape.SetAsBox(mazeBox.Width/2f*0.01f, mazeBox.Height/2f*0.01f, new Vector2(x*.30f, y*0.30f),0);
            
            return bodyShape;

        }
 mazeBody.CreateFixture(CreateTile(x, y), 1.0f);





protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();


/**So now i need to render all the x,y textures*/
            spriteBatch.Draw(mazeBox, mazeBody.Position / 0.01f, null, Color.White, mazeBody.Rotation, new Vector2(mazeBox.Width / 2f, mazeBox.Height / 2f), 1, SpriteEffects.None, 0);
            

         
            spriteBatch.End();

            base.Draw(gameTime);
        }

Jul 20, 2010 at 1:00 PM
Your physics information is not your rendering information. Create some transforms based on the maze's position and rotation, then just go through the same data you used to create the maze and draw boxes.
Jul 26, 2010 at 7:54 AM

Do you know of any examples of how this is done, I havent done anything like this before so any examples in other langs will do.