World and Gravity Settings - Boxes floating upwards

Oct 30, 2010 at 2:15 PM

Hi I'm just starting out with farseer physics using xna 4.0 and the most recent build of farseer physics.

I'm writing to ask my first question, I've got my first fixture drawing, but its floating up and not falling down as excepted. Below is a cut from my code, shorten.

I also had a problem with using vector2 and the farseer library, as it defined in the library and the framework.dll.

Thanks and I look forward to any information on either problem.

World world;
Vector2 gravity = new Vector2(0, -20);

LoadContent()
{
world = new World(gravity);

rectangle = new Rectangle(6, 6, 100, 100);

rectangleTexture = Content.Load<Texture2D>("white_square");

rectangleFixture = FixtureFactory.CreateRectangle(world, rectangle.Width, rectangle.Height, 1, new Vector2(rectangle.X, rectangle.Y));

rectangleFixture.Body.BodyType = BodyType.Dynamic;
rectangleFixture.Restitution = 0.3f;
rectangleFixture.Friction = 0.5f;
}

Update(GameTime gameTime)
{
rectangle.X = (int)rectangleFixture.Body.Position.X;
rectangle.Y = (int)rectangleFixture.Body.Position.Y;
           world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f);
}

Draw()
{
spriteBatch.Draw(rectangleTexture, rectangle, Color.Green);
}


Oct 31, 2010 at 11:12 AM
Your fixture's moving down alright, but because Spritebatch takes negative numbers as up, it's drawing incorrectly; take a look at the Helloworld example under Downloads use the Debug view but draw spritebatch on top- that should make it clearer what's going on :)