Box2DLayer::Box2DLayer(){
//setTouchEnabled(true);
CCLayer::init();
b2Vec2 gravity;
gravity.Set(4440, -400000.0f);
m_world = new b2World(gravity);
m_world->SetAllowSleeping(true);
m_world->SetContinuousPhysics(true);
schedule(schedule_selector(Box2DLayer::update));
m_debugDraw = new GLESDebugDraw(12.0f);
uint32 flags = 0;
flags +=b2Draw::e_shapeBit;
flags +=b2Draw::e_pairBit;
flags +=b2Draw::e_jointBit;
flags +=b2Draw::e_centerOfMassBit;
flags +=b2Draw::e_aabbBit;
m_debugDraw->SetFlags(flags);
m_world->SetDebugDraw(m_debugDraw);
b2BodyDef myBodyDef;
myBodyDef.type = b2_dynamicBody;
myBodyDef.position.Set(20,20);
myBodyDef.angle = 0;
b2Body* db = m_world->CreateBody(&myBodyDef);
//db->SetActive(true);
b2PolygonShape shape;
shape.SetAsBox(1,1);
b2FixtureDef boxFix;
boxFix.shape = &shape;
boxFix.density =1.0f;
db->CreateFixture(&boxFix);
this->setAccelerometerEnabled(true); // 在层里启用重力感应
db->SetLinearVelocity(b2Vec2(0,-10));
db->SetTransform(b2Vec2(30,30), 45);
}