本文整理汇总了C++中PhysicsSprite::setCollisionGroup方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsSprite::setCollisionGroup方法的具体用法?C++ PhysicsSprite::setCollisionGroup怎么用?C++ PhysicsSprite::setCollisionGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsSprite
的用法示例。
在下文中一共展示了PhysicsSprite::setCollisionGroup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
//.........这里部分代码省略.........