Gah

Topics: Developer Forum
Oct 8, 2011 at 10:56 PM

Ok I have read through the sparse documentation and looked through the demos and still don't know what I am doing wrong.

 

I have the following to try and set everything up:

 

GameWorld = new World(new Vector2(0, -4));
PlayerBody = BodyFactory.CreateRectangle(GameWorld, 24, 36, 0);
PlayerShape = new PolygonShape(PolygonTools.CreateRectangle(24, 36), 1);
PlayerBody.BodyType = BodyType.Dynamic;
PlayerBody.FixedRotation = true;
PlayerFixture = PlayerBody.CreateFixture(PlayerShape);
PlayerBody.Position = new Vector2(0, 0);
GameWorld.BodyList.Add(PlayerBody);

and then in my Update:

GameWorld.Step(TimeManager.SecondDifference);
GamePlayer.X = PlayerFixture.Body.Position.X;
GamePlayer.Y = PlayerFixture.Body.Position.Y;

I tried PlayerFixture positions and PlayBody positions but each give nullreferenceexception. What am I forgetting to initialize?

Oct 9, 2011 at 10:02 AM

first of all

PlayerShape = new PolygonShape(PolygonTools.CreateRectangle(24, 36), 1);

PlayerFixture = PlayerBody.CreateFixture(PlayerShape);

is not needed because you allready create a rectangle with

BodyFactory.CreateRectangle(GameWorld, 24, 36, 0); <- set 0 to 1

also i think this is not allowed (may i'm wrong)

GameWorld.BodyList.Add(PlayerBody);
but i have no idea why it gives you a nullreference exception