I am playing around with CocosSharp and Box2D. I'm trying to create a world and add a ground body to it. Here's my code:
var gravity = b2Vec2.Zero;
gravity.Set(0f, -9.8f);
world = new b2World(gravity);
world.SetAllowSleeping(false);
world.SetContinuousPhysics(true);
var groundBodyDef = new b2BodyDef();
groundBodyDef.position.Set(0, 0);
var groundBody = world.CreateBody(groundBodyDef);
The problem comes at the last line. world.CreateBody(groundBodyDef)
returns null.
I looked at the implementation for b2World.CreateBody and saw that it will only return null if IsLocked is true. My understanding is that IsLocked is true when the world is stepping. However, I see when running my code that IsLocked is actually false, yet CreateBody still returns null.
All the examples I've looked at follow the same basic setup of the b2World. Is there something I'm missing?
I'm testing this on an Android emulator, if that makes a difference.
EDIT 5/27: After learning more about the problem, I now know that there is some important information that I didn't think was necessary to include in my original question. I was wrong. I used the CocosSharp Visual Studio template to create the solution and projects. This is the reason the whole thing doesn't work on Android. I'll explain in the answer.