How to Create World in Box2D in iOS Game Development(iPhone,iPad)

Here Lets have a look creating world in box2D.
Every Box2D program begins with the creation of a b2World object. b2World is the physics hub that
manages memory, objects, and simulation. You can allocate the physics world on the stack, heap, or
data section.
in Header file Create an object for World like this,

b2World *myWorld;
in .mm file create the world

first we have to create gravity.

b2Vec2 gravity = new b2Vec2(0.0f,-10.0f);

and set the sleep parameter for world
bool doSleep = true;

Now , lets create world object

myWorld = new b2World(gravity,doSleep);

Delete World:
when your app exits you have to destroy the world what you have created

delete myWorld;
In next ,lets add some stuff into world

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *