my bodys are intersect !

Jul 27, 2011 at 5:28 PM

hi all


I have an error with my first attempt to create a simple physics


this is the result !!! :(


i did try every thing but :( no progress


plz help

and this is the code



 using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FarseerPhysics;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Controllers;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;

namespace OsamaGame

public class Intro : Microsoft.Xna.Framework.DrawableGameComponent
SpriteBatch spriteBatch;

private const float MeterInPixels = 64f;

World world;
Body myBody;
Body ground;

Texture2D circleSprite;
Texture2D groundSprite;

public Intro(Game game)
: base(game)
// TODO: Construct any child components here

// Initializing Method
public override void Initialize()


// Load content
protected override void LoadContent()
spriteBatch = new SpriteBatch(Game.GraphicsDevice);

circleSprite = Game.Content.Load<Texture2D>(@"Intro\circleSprite");
groundSprite = Game.Content.Load<Texture2D>(@"Intro\groundSprite");

//Create a World object with zero gravity
world = new World(new Vector2(0f, 10f));

//We create a body object and make it dynamic (movable)
myBody = BodyFactory.CreateCircle(world, circleSprite.Width / (2f * MeterInPixels), 1f, new Vector2(0f / MeterInPixels, 100f / MeterInPixels));
myBody.BodyType = BodyType.Dynamic;

ground = BodyFactory.CreateRectangle(world, groundSprite.Width / MeterInPixels, groundSprite.Height / MeterInPixels, 1f, new Vector2(0f, 400f / MeterInPixels));
ground.IsStatic = true;
// Give it some bounce and friction
myBody.Restitution = 0.3f;
myBody.Friction = 0.5f;

ground.Restitution = 0.3f;
ground.Friction = 0.5f;


// Update methode
public override void Update(GameTime gameTime)
if (Keyboard.GetState().IsKeyDown(Keys.Space))
myBody.ApplyLinearImpulse(new Vector2(0f, -3f));
world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f );

// Draw
public override void Draw(GameTime gameTime)
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

spriteBatch.Draw(circleSprite, myBody.Position * MeterInPixels, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
spriteBatch.Draw(groundSprite, ground.Position * MeterInPixels, Color.White);



Jul 28, 2011 at 2:52 PM

fixed :(

i didn't use the origin in Draw method so that the draw wasn't correct :(

but still don't know why ??