3

I have no idea why but I cant seem to find out why this isn't working... I'm trying to make something really simple, like something that just falls off the screen.

It seems like with the latest download and the first example code on the site, I'm still wrong.

I have this:

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections;
using Microsoft.Xna.Framework.Input;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Collision.Shapes;


namespace Cross {
    public class Game1 : Microsoft.Xna.Framework.Game {
        GraphicsDeviceManager graphics;

        public Game1() {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth = 1200;

            this.Window.Title = "Game";
        }


        protected override void Initialize() {
            World world = new World(Vector2.Zero);

            Body myBody = world.CreateBody();
            myBody.BodyType = BodyType.Dynamic;

            CircleShape circleShape = new CircleShape(0.5f);
            Fixture fixture = myBody.CreateFixture(circleShape);

            base.Initialize();
        }

        protected override void LoadContent() {

        }

        protected override void UnloadContent() {
        }


        protected override void Update(GameTime gameTime) {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime) {
            base.Draw(gameTime);
        }
    }
}

But I get 2 errors:

No CreateBody() method (there is an AddBreakableBody() though)

'FarseerPhysics.Dynamics.World' does not contain a definition for 'CreateBody' and no extension method 'CreateBody' accepting a first argument of type 'FarseerPhysics.Dynamics.World' could be found (are you missing a using directive or an assembly reference?)

CircleShape constructor takes 2 arguments (this ones easy but still error in the example)

'FarseerPhysics.Collision.Shapes.CircleShape' does not contain a constructor that takes 1 arguments

I've tried so many things and I'm confused why I can get this. Does this code work for others? Is my dll messed up?

Mark Lalor
  • 7,820
  • 18
  • 67
  • 106

1 Answers1

3

Their example is wrong, you're right! (I'm surprised that they have such glaring errors.)

Go to the class CircleShape and see which order the parameters go. A circle is defined by a position and a radius, not just a radius.

Then search your project for CreateBody(), to see where that method should be called from.

Olhovsky
  • 5,466
  • 3
  • 36
  • 47
  • 2
    Ahh `FarseerPhysics.Factories.BodyFactory.CreateBody()` maybe – Mark Lalor May 08 '11 at 20:53
  • 1
    I also recommend downloading the XNA Testbed examples as they show how to use certain methods: http://farseerphysics.codeplex.com/releases/view/64108. You can also get more code samples by browsing the 'Sample' section in the source: http://farseerphysics.codeplex.com/SourceControl/changeset/view/88395 – keyboardP May 08 '11 at 20:55
  • @keyboardp Thanks a lot! That second link gave me some source that helped me a lot – Mark Lalor May 08 '11 at 21:02
  • Yes, it seems like the documentation is outdated. Body factory solves this issue in the latest release (3.5). Note that the documented version is 3.3 which in my opinion is too soon for such huge changes to code... – Serguei Fedorov Aug 28 '13 at 00:42