physicsSimulatorView (DEBUG) in a DLL (woot)

Topics: Developer Forum
Oct 18, 2009 at 3:26 AM

Not sure if this is formally coming down the pipe, or even how long my stab at it will last... that said... here's the DLL I use so you can easily add the DEBUG view (and AABB/collision verticies also) in your projects, that can be seen on the Sample Projects.

To add to your project:

  1. Download the linked zip file (HERE) and extract anywhere
  2. Add the Font files in the .\Content\Fonts\ Folder to your project, maintaining the same folder structure (ie. [Project]\Content\Fonts\[Add Here])
  3. Add a Project Reference to the FarseerDebug.dll (be sure you're adding the reference to the project, not the Content)

Below is the only code integration needed on a plain vanilla XNA template.  Enjoy...

 

...
using FarseerGames.FarseerPhysics;
using FarseerGames.Debug;

namespace FarseerDebugView {
public class Game1 : Microsoft.Xna.Framework.Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
PhysicsSimulator physicsSimulator;
PhysicsSimulatorView physicsSimulatorView;


private Texture2D earth;

public Game1() {
graphics = new GraphicsDeviceManager(this);
physicsSimulator = new PhysicsSimulator(new Vector2(0, 0));
physicsSimulatorView = new PhysicsSimulatorView(physicsSimulator);

Content.RootDirectory = "Content";
}

protected override void Initialize() {
base.Initialize();
}

protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);

physicsSimulatorView.LoadContent(GraphicsDevice, Content);

earth = Content.Load<Texture2D>("earth");
}

protected override void UnloadContent() { }

protected override void Update(GameTime gameTime) {
// Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

base.Update(gameTime);
}

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

spriteBatch.Begin();

spriteBatch.Draw(earth, new Vector2(400, 300), Color.White);

physicsSimulatorView.Draw(spriteBatch);


spriteBatch.End();

base.Draw(gameTime);
}
}
}

 

 

Oct 18, 2009 at 11:17 PM

Awesome!! I was just looking for this when you posted it hehe.

 

Thanks, very useful.

JL

Sep 2, 2010 at 5:50 PM

This seems to be exactly what im looking for. however. im getting a "NullReferenceException was unhandled" error on the following line:

physicsSimulatorView.LoadContent(GraphicsDevice, Content);

 

I was wondering if anyone had any ideas on why that is. my code is as follows:

 

using FarseerGames.FarseerPhysics.Factories;
using FarseerGames.Debug;

namespace Gunslingers // begin Test
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        // Create Physics symulator
        PhysicsSimulator simulator = new PhysicsSimulator(new Vector2(0, 250));
        PhysicsSimulatorView physicsSimulatorView;

        GraphicsDeviceManager graphics;
        ContentManager Content;

        SpriteBatch spriteBatch;
        


        Map map = new Map();
        Character lucas = new Character();


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content = new ContentManager(Services, "Content");
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            physicsSimulatorView.LoadContent(GraphicsDevice, Content);

            map.loadContent(Content, simulator);
            lucas.loadContent(Content, simulator);
        }


        protected override void UnloadContent()      { }


        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            lucas.KeyInput();
            lucas.Move();


            simulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
            base.Update(gameTime);
        }


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



            // TODO: Add your drawing code here
            spriteBatch.Begin();

            map.Draw(spriteBatch);
            lucas.Draw(spriteBatch);

            physicsSimulatorView.Draw(spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }


    }
}

What am i missing??!!