simple BreakableBody example

Sep 20, 2011 at 1:47 PM

where i find simple BreakableBody example without using SampleFramwork? I can't understand how drawing BreakableBody with XNA.
p.s. sorry for my English.

Sep 21, 2011 at 1:50 PM

ok, i have the code

protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            red = Content.Load<Texture2D>("red");
            world = new World(new Vector2(0, 100));
            uint[] data = new uint[red.Width * red.Height];
            red.GetData(data);           
            Vector2 position = new Vector2(120, 120);
            compund = BodyFactory.CreateRectangle(world, red.Width, red.Height, 1, position);            
            compund.BodyType = BodyType.Dynamic;
            compund.Mass = 1;
            compund.Restitution = 0.8f;
            compund.Friction = 0.5f;
            Vertices _list = PolygonTools.CreatePolygon(data,red.Width);
            List<Vertices> _comp = BayazitDecomposer.ConvexPartition(_list);
                        
            breakBody = new BreakableBody(_comp, world, 1);
            breakBody.MainBody.BodyType = BodyType.Dynamic;
            breakBody.MainBody.Position = position;
            breakBody.MainBody.Mass = 5;
            breakBody.Strength = 1;
            breakBody.MainBody.Restitution = 0.8f;
            breakBody.MainBody.Friction = 0.1f;
            world.AddBreakableBody(breakBody);
            
            Vertices border = new Vertices(4);
            border.Add(new Vector2(0, 480));
            border.Add(new Vector2(640, 480));
            border.Add(new Vector2(640, 0));
            border.Add(new Vector2(0, 0));
            
            borderBody = BodyFactory.CreateLoopShape(world, border);
            borderBody.CollisionCategories = Category.All;
            borderBody.CollidesWith = Category.All;

            // TODO: use this.Content to load your game content here
        }

...

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

            spriteBatch.Begin();
            
            Vector2 origin = new Vector2(red.Width / 2f, red.Height / 2f);
            spriteBatch.Draw(red, compund.Position, null, Color.White, compund.Rotation, origin, 1f, SpriteEffects.None, 0f);
            base.Draw(gameTime);
            spriteBatch.End();
        }


i see red square. he is falling. and....nothing. what i do wrong? I needed just one simple example how use BreakableBody and how draw result, please...