本文整理汇总了C++中PhysicsSprite::getBody方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsSprite::getBody方法的具体用法?C++ PhysicsSprite::getBody怎么用?C++ PhysicsSprite::getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsSprite
的用法示例。
在下文中一共展示了PhysicsSprite::getBody方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMouseJoint
////////////////////////////////////////////////////////////////////////////////
// マウスジョイント取得
b2MouseJoint* HelloWorld::getMouseJoint(cocos2d::CCPoint p) {
b2Vec2 locationWorld = b2Vec2(p.x/PTM_RATIO, p.y/PTM_RATIO);
CCNode* parent = getChildByTag(kTagParentNode);
CCArray* children = parent->getChildren();
CCObject* data = NULL;
CCARRAY_FOREACH(children, data)
{
PhysicsSprite* spr = (PhysicsSprite*)data;
if (spr != NULL) {
// スプライトに付与されているBodyを取得
b2Body* b = spr->getBody();
b2Fixture *f = b->GetFixtureList();
if (f->TestPoint(locationWorld)) {
b2MouseJointDef md;
b2BodyDef groundBodyDef;
b2MouseJoint* mouseJoint;
b2Body* groundBody = world->CreateBody(&groundBodyDef);
md.bodyA = groundBody;//ground Body
md.bodyB = b;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 1000.0f * b->GetMass();
b->SetAwake(true);
// ジョイント取得
mouseJoint = (b2MouseJoint *)world->CreateJoint(&md);
return mouseJoint;
}
}
}
示例2: SneakyJoystick
HelloWorld::HelloWorld()
{
hello = this;
// Define the gravity vector.
b2Vec2 gravity;
gravity.Set(0.0f, 0.0f);
// Do we want to let bodies sleep?
bool doSleep = true;
// Construct a world object, which will hold and simulate the rigid bodies.
world = new b2World(gravity);
world->SetAllowSleeping(doSleep);
world->SetContinuousPhysics(true);
joyStick = new SneakyJoystick();
joyStick->autorelease();
joyStick->initWithRect(CCRectZero);
joyStick->setAutoCenter(true);
joyStick->setHasDeadzone(true);
joyStick->setDeadRadius(10);
SneakyJoystickSkinnedBase *joystickSkin = new SneakyJoystickSkinnedBase();
joystickSkin->autorelease();
joystickSkin->init();
joystickSkin->setBackgroundSprite(CCSprite::create("button-default.png"));
joystickSkin->setThumbSprite(CCSprite::create("button-disabled.png"));
joystickSkin->getThumbSprite()->setScale(0.5f);
joystickSkin->setPosition(ccp(50, 50));
joystickSkin->setJoystick(joyStick);
// load shapes
GB2ShapeCache::sharedGB2ShapeCache()->addShapesWithFile("physicalTest.plist");
setTouchEnabled(true);
setAccelerometerEnabled( true );
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
// m_debugDraw = new GLESDebugDraw( PTM_RATIO );
// world->SetDebugDraw(m_debugDraw);
//
// uint32 flags = 0;
// flags += b2Draw::e_shapeBit;
// flags += b2Draw::e_jointBit;
// // flags += b2Draw::e_aabbBit;
// // flags += b2Draw::e_pairBit;
// // flags += b2Draw::e_centerOfMassBit;
// m_debugDraw->SetFlags(flags);
//
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(screenSize.width/2/PTM_RATIO, screenSize.height/2/PTM_RATIO);
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
b2Body *groundBody = world->CreateBody(&groundBodyDef);
// Define the ground box shape.
b2PolygonShape groundBox;
/*
// bottom
groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, -screenSize.height/2/PTM_RATIO), 0);
groundBody->CreateFixture(&groundBox, 0);
// top
groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, screenSize.height/2/PTM_RATIO), 0);
groundBody->CreateFixture(&groundBox, 0);
// left
groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(-screenSize.width/2/PTM_RATIO, 0), 0);
groundBody->CreateFixture(&groundBox, 0);
// right
groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(screenSize.width/2/PTM_RATIO, 0), 0);
groundBody->CreateFixture(&groundBox, 0);
*/
//initBG
initBG();
PhysicsSprite *sprite = PhysicsSprite::create("missile", CCPointMake(screenSize.width/2/32, screenSize.height/2/32), world);
sprite->setCollisionGroup(-10);
sprite->setTag(1);
playerBody = sprite->getBody();
bgLayer->addChild(sprite);
Weapon *gun = Weapon::create("SlienceBullet.png");
sprite->addChild(gun);
PhysicsSprite *sprite_2 = PhysicsSprite::create("missile", CCPointMake(screenSize.width/2/32, screenSize.height/2/32), world);
//.........这里部分代码省略.........