cocos2dx box2d 炮弹不打自己人怎么做
推荐于2016-05-30
展开全部
b2BodyDef groundBodyDef;
groundBodyDef.type = b2_staticBody;
groundBodyDef.position.Set(0, 0);//相当于cocos2d的锚点
b2Body* groundBody = _world->CreateBody(&groundBodyDef);
//b2FixtureDef--->b2Fixture
b2EdgeShape groundShape;
b2FixtureDef groundFixDef;
groundFixDef.shape = &groundShape;
groundShape.Set(b2Vec2(0, 0), b2Vec2(screenSize.width / PTM_RATIO, 0)); //屏幕的底部墙
groundBody->CreateFixture(&groundFixDef);
groundShape.Set(b2Vec2(0, 0), b2Vec2(0, screenSize.height / PTM_RATIO)); //屏幕的左边墙
groundBody->CreateFixture(&groundFixDef);
groundShape.Set(b2Vec2(0, screenSize.height / PTM_RATIO),
b2Vec2(screenSize.width / PTM_RATIO, screenSize.height / PTM_RATIO)); //屏幕的上部墙
groundBody->CreateFixture(&groundFixDef);
groundShape.Set(b2Vec2(screenSize.width / PTM_RATIO, 0),
b2Vec2(screenSize.width / PTM_RATIO, screenSize.height / PTM_RATIO)); //屏幕的右边墙
groundBody->CreateFixture(&groundFixDef);
groundBodyDef.type = b2_staticBody;
groundBodyDef.position.Set(0, 0);//相当于cocos2d的锚点
b2Body* groundBody = _world->CreateBody(&groundBodyDef);
//b2FixtureDef--->b2Fixture
b2EdgeShape groundShape;
b2FixtureDef groundFixDef;
groundFixDef.shape = &groundShape;
groundShape.Set(b2Vec2(0, 0), b2Vec2(screenSize.width / PTM_RATIO, 0)); //屏幕的底部墙
groundBody->CreateFixture(&groundFixDef);
groundShape.Set(b2Vec2(0, 0), b2Vec2(0, screenSize.height / PTM_RATIO)); //屏幕的左边墙
groundBody->CreateFixture(&groundFixDef);
groundShape.Set(b2Vec2(0, screenSize.height / PTM_RATIO),
b2Vec2(screenSize.width / PTM_RATIO, screenSize.height / PTM_RATIO)); //屏幕的上部墙
groundBody->CreateFixture(&groundFixDef);
groundShape.Set(b2Vec2(screenSize.width / PTM_RATIO, 0),
b2Vec2(screenSize.width / PTM_RATIO, screenSize.height / PTM_RATIO)); //屏幕的右边墙
groundBody->CreateFixture(&groundFixDef);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询