本文整理汇总了C++中PhysicsBody::setCollisionBitmask方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::setCollisionBitmask方法的具体用法?C++ PhysicsBody::setCollisionBitmask怎么用?C++ PhysicsBody::setCollisionBitmask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsBody
的用法示例。
在下文中一共展示了PhysicsBody::setCollisionBitmask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addPhysics
void Person::addPhysics()
{
auto size = (this->getBoundingBox()).size;
log("%lf %lf", size.width, size.height);
auto material = PhysicsMaterial(100.0f, 0.01f, 1.0f);
if(_type == TYPE::HERO) size.width /= 2;
PhysicsBody *body = PhysicsBody::createBox(Size(size.width,size.height),material);
// body->addShape(PhysicsShapeBox::create(Size(size.width,size.height),material));
body->setCategoryBitmask(_type);
if(_type == TYPE::MONSTER)
{
body->setCollisionBitmask(TYPE::MONSTER | TYPE::BRICK | TYPE::GROUND |
TYPE::TANGH | TYPE::BULLET | TYPE::BOSS | TYPE::PLANK);
body->setContactTestBitmask(TYPE::MONSTER | TYPE::HERO | TYPE::BRICK |
TYPE::TANGH | TYPE::BULLET | TYPE::BOSS);
}
else if(_type == TYPE::HERO)
{
body->setCollisionBitmask( TYPE::HERO | TYPE::GROUND | TYPE::TANGH | TYPE::PLANK);
body->setContactTestBitmask(TYPE::MONSTER | TYPE::HERO | TYPE::GROUND |
TYPE::TANGH | TYPE::BULLET | TYPE::TRAP | TYPE::BOSS |
TYPE::BULLETENEMY | TYPE::PLANK | TYPE::BUFF);
}
else if(_type == TYPE::BOSS)
{
body->setCollisionBitmask( TYPE::HERO | TYPE::GROUND | TYPE::BOSS | PLANK);
body->setContactTestBitmask( TYPE::HERO | TYPE::GROUND | TYPE::BOSS);
}
body->setDynamic(true);
body->setLinearDamping(0.0f);
body->setRotationEnable(false);
body->setGravityEnable(true);
this->setPhysicsBody(body);
}
示例2: addToParent
void Tree::addToParent(Node* parent)
{
parent -> addChild( mLeavesSprite);
mLeavesSprite->setTag(1);
PhysicsBody* mLeavesBody = PhysicsBody::createCircle(mLeavesSize.width / 4, PHYSICSBODY_MATERIAL_DEFAULT);
mLeavesBody->setContactTestBitmask(1);
mLeavesBody->setCollisionBitmask(0);
mLeavesBody->setCategoryBitmask(1);
mLeavesNode -> setPhysicsBody( mLeavesBody);
parent->addChild(mLeavesNode);
mLeavesNode->setPosition(mLeavesPosition);
parent -> addChild( mBodySprite);
mBodySprite->setTag(1);
PhysicsBody* mBodyBody = PhysicsBody::createBox(mBodySize, PHYSICSBODY_MATERIAL_DEFAULT);
mBodyBody->setContactTestBitmask(1);
mBodyBody->setCollisionBitmask(0);
mBodyBody->setCategoryBitmask(1);
mBodyNode -> setPhysicsBody( mBodyBody);
parent->addChild(mBodyNode);
mBodyNode->setPosition(mPosition);
parent -> addChild( mRootSprite);
mLeavesSprite->setAnchorPoint(Vec2(0.5, -0.8));
mBodySprite -> setAnchorPoint(Vec2(0.5, 0));
mBodySprite -> setPosition(Vec2(mBodyPosition.x, mBodyPosition.y - mBodySprite->getContentSize().height / 2));
mLeavesSprite -> setPosition(mBodySprite->getPosition());
Rotation();
}
示例3: configPipeRandom
void PipeSprite::configPipeRandom()
{
Size visiableSize = Director::getInstance()->getVisibleSize();
Vec2 visiableOrigin = Director::getInstance()->getVisibleOrigin();
/**********************config upper pipe********************************/
mUpperPipe->setPosition(Vec2(0, mPipeAccessHeight + 60));
upperPipeExpand->setPosition(mUpperPipe->getPosition().x, mUpperPipe->getContentSize().height);
upperPipeExpand->setScaleY((visiableSize.height - mUpperPipe->getPosition().y - mUpperPipe->getContentSize().height) / upperPipeExpand->getContentSize().height);
/**********************config upper pipe********************************/
/**********************config bottom pipe********************************/
mBottomPipe->setPosition(Vec2(0, mPipeAccessHeight - 60));
bottomPipeExpand->setPosition(0, -mBottomPipe->getPosition().y + mLandHeight);
bottomPipeExpand->setScaleY((mBottomPipe->getPosition().y - mLandHeight) / bottomPipeExpand->getContentSize().height);
/**********************config bottom pipe********************************/
/****************add upper physics body*******************/
if (mUpperPipe->getPhysicsBody() != nullptr)
{
mUpperPipe->removeComponent(mUpperPipe->getPhysicsBody());
}
PhysicsBody * newUpperPipeBody = PhysicsBody::createBox(Size(mUpperPipe->getContentSize().width,
visiableSize.height - mUpperPipe->getPosition().y),
PhysicsMaterial(1.0, 1.0, 0));
newUpperPipeBody->setPositionOffset(Vec2(0, (visiableSize.height - mUpperPipe->getPosition().y - mUpperPipe->getContentSize().height) / 2));
newUpperPipeBody->setGravityEnable(false);
newUpperPipeBody->setDynamic(false);
newUpperPipeBody->setContactTestBitmask(1);
newUpperPipeBody->setCollisionBitmask(2);
mUpperPipe->setPhysicsBody(newUpperPipeBody);
/****************add upper physics body*******************/
/****************add bottom physics body*******************/
if (mBottomPipe->getPhysicsBody() != nullptr)
{
mBottomPipe->removeComponent(mBottomPipe->getPhysicsBody());
}
PhysicsBody * newBottomPipeBody = PhysicsBody::createBox(Size(mBottomPipe->getContentSize().width,
mBottomPipe->getPosition().y - mLandHeight + mBottomPipe->getContentSize().height),
PhysicsMaterial(1.0, 1.0, 0));
newBottomPipeBody->setPositionOffset(Vec2(0, -(mBottomPipe->getPosition().y - mLandHeight) / 2));
newBottomPipeBody->setGravityEnable(false);
newBottomPipeBody->setDynamic(false);
newBottomPipeBody->setContactTestBitmask(1);
newBottomPipeBody->setCollisionBitmask(2);
mBottomPipe->setPhysicsBody(newBottomPipeBody);
/****************add bottom physics body*******************/
}
示例4: init
bool Car::init(string fileName)
{
if (!Node::init())
return false;
//------------- Khởi tạo sprite chính -------------
_sprite = Sprite::create(fileName);
_sprite->setPosition(0, 0);
_sprite->setAnchorPoint(Vec2(0.25, 0.25));
this->addChild(_sprite);
//------------- Physic Body --------------
body = PhysicsBody::createBox(Size(_sprite->getContentSize().width / 2, _sprite->getContentSize().height / 2), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
body->setDynamic(false);
body->setTag(Tags::OBSTRUCTION);
body->setCollisionBitmask(1);
body->setContactTestBitmask(1);
this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
this->setPhysicsBody(body);
//Mai xe
auto nodeCar = Node::create();
nodeCar->setPosition(_sprite->getContentSize().width * 2.1 / 4, _sprite->getContentSize().height * 2.3 / 3);
nodeCar->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_sprite->addChild(nodeCar);
PhysicsBody * bodyNodeCar = PhysicsBody::createBox(Size(_sprite->getContentSize().width * 2.5 / 5, _sprite->getContentSize().height / 3), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
bodyNodeCar->setTag(Tags::MAIXE);
bodyNodeCar->setDynamic(false);
bodyNodeCar->setContactTestBitmask(1);
bodyNodeCar->setCollisionBitmask(1);
nodeCar->setPhysicsBody(bodyNodeCar);
//Score
auto nodeScore = Node::create();
nodeScore->setPosition(_sprite->getContentSize().width * 2.1 / 4, _sprite->getContentSize().height);
nodeScore->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_sprite->addChild(nodeScore);
PhysicsBody * bodyNodeScore = PhysicsBody::createBox(Size(_sprite->getContentSize().width * 2.5 / 5, Config::screenSize.height), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
bodyNodeScore->setTag(Tags::NODE_SCORE);
bodyNodeScore->setDynamic(false);
bodyNodeScore->setCategoryBitmask(0x01);
bodyNodeScore->setContactTestBitmask(1);
bodyNodeScore->setCollisionBitmask(0x02);
nodeScore->setPhysicsBody(bodyNodeScore);
return true;
}
示例5: init
bool Monster::init()
{
mutex = PTHREAD_MUTEX_INITIALIZER;
status = DONE;
auto snakeTexture = TextureCache::sharedTextureCache()->addImage(
basic.getCString());
float dWidth = snakeTexture->getContentSize().width / cntWidth;
float dHeight = snakeTexture->getContentSize().height / cntHeight;
this->setAnchorPoint(Vec2(0.5,32/dHeight));
PhysicsBody *body = PhysicsBody::createBox(Size(60,60));
body->setPositionOffset(Vec2(0,64/4-dHeight/4));
body->setRotationEnable(false);
body->setGravityEnable(false);
body->setContactTestBitmask(0xffffffff);
body->setCollisionBitmask(0xffffffff);
this->setPhysicsBody(body);
this->setTag(MONSTER);
auto listener = EventListenerCustom::create("main_action",
CC_CALLBACK_1(Monster::receive,this));
_eventDispatcher->addEventListenerWithFixedPriority(listener, 1);
return true;
return false;
}
示例6: init
bool guaiwu_js::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
auto root_layer = CSLoader::createNode("LayerUI/Other/guaiwu.csb");
addChild(root_layer);
auto rooaby = root_layer->getChildByName<Node*>("FileNode_1")->getChildByName<Sprite*>("anim_guaiwu_zo0001_2");
PhysicsBody* phybody = PhysicsBody::createBox(Size(rooaby->getContentSize().width-8, rooaby->getContentSize().height-20));
phybody->setTag(400001);
phybody->setMass(3000);
phybody->setRotationEnable(false);
phybody->setCategoryBitmask(0x01);
phybody->setCollisionBitmask(0x02);
phybody->setContactTestBitmask(0x01);
phybody->setDynamic(true);
rooaby->setPhysicsBody(phybody);
guaiwu = CSLoader::createTimeline("Node/animation/guaiwujs.csb");
guaiwu->gotoFrameAndPlay(0,35, true);
root_layer->runAction(guaiwu);
scheduleUpdate();
//添加碰撞事件
auto collisionlistener = EventListenerPhysicsContact::create();
collisionlistener->onContactBegin =CC_CALLBACK_1(guaiwu_js::onCollisionBegin, this);
collisionlistener->onContactSeparate = CC_CALLBACK_1(guaiwu_js::onContactSeparate,this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(collisionlistener, this);
return true;
}
示例7: initBody
void SpeedUpProtect::initBody()
{
auto s = getContentSize();
Vec2 vec[7] =
{
Vec2(0,0),
Vec2(s.width * 0.1, s.height * 0.4),
Vec2(s.width * 0.26, s.height * 0.72),
Vec2(s.width * 0.5, s.height),
Vec2(s.width * 0.74, s.height * 0.72),
Vec2(s.width * 0.9, s.height * 0.4),
Vec2(s.width,0),
};
PhysicsBody* body = PhysicsBody::createPolygon(vec, 7, PHYSICSBODY_MATERIAL_DEFAULT, Vec2(-s.width*0.5,-s.height*0.5));
body->setGravityEnable(false);
body->setRotationEnable(false);
body->setDynamic(false);
body->setMass(10000000);
body->setCategoryBitmask(SELF_SCOPE_CATEGORYBITMASK);
body->setCollisionBitmask(SELF_SCOPE_COLLISIONBITMASK);
body->setContactTestBitmask(SELF_SCOPE_CONTACTTESTBITMASK);
setPhysicsBody(body);
setInvincible(true);
m_ContactPro.hurts = -Ene_Plane_Hp_max - 10;
}
示例8: initPhyscsObject
void ShowLayer::initPhyscsObject(Rect* m)
{
for (int i = 0; i < 26; i++)
{
Sprite* sp = Sprite::create();
auto maskLayer = LayerColor::create(Color4B(0, 0, 255, 200));
maskLayer->setContentSize(m[i].size);
maskLayer->setAnchorPoint(Vec2(0, 0));
sp->addChild(maskLayer, 15);
PhysicsBody* playerBody = PhysicsBody::createBox(m[i].size, PHYSICSBODY_MATERIAL_DEFAULT);
playerBody->setDynamic(false);
//设置质量
playerBody->getShape(0)->setMass(100);
//设置物体是否受重力系数影响
playerBody->setGravityEnable(false);
playerBody->setCategoryBitmask(3);
playerBody->setContactTestBitmask(3);
playerBody->setCollisionBitmask(3);
sp->setContentSize(m[i].size);
sp->setPosition(Vec2(m[i].getMidX(), m[i].getMidY()));
sp->setAnchorPoint(Vec2(0.0, 0.0));
sp->setPhysicsBody(playerBody);
this->addChild(sp);
}
}
示例9: reload
void PFMPlayer::reload()
{
if(_preset == NULL)
return;
for(int i=0;i<_preset->components.size();i++)
{
PFMComponent* component = _preset->components[i];
if(component->componentClass == "Sprite")
{
PFMSpriteComponent* spriteComponent = dynamic_cast<PFMSpriteComponent*>(component);
PFMSprite* sprite = PFMSprite::createWithComponent(spriteComponent);
Size size = sprite->getBoundingBox().size;
PhysicsBody* physicsBody = PhysicsBody::createBox(sprite->getBoundingBox().size);
physicsBody->setCollisionBitmask(0);
physicsBody->setCategoryBitmask(PFMCollideMaskBitsPlayer);
physicsBody->setContactTestBitmask(PFMCollideMaskBitsEnemyBullet | PFMCollideMaskBitsEnemy);
setPhysicsBody(physicsBody);
addChild(sprite);
}
else if(component->componentClass == "BulletGun")
{
PFMBulletGunComponent* bulletGunComponent = dynamic_cast<PFMBulletGunComponent*>(component);
PFMBulletGun* bulletGun = PFMBulletGun::createWithComponent(bulletGunComponent);
bulletGun->isHostByPlayer = true;
bulletGun->isAutoShoot = true;
addChild(bulletGun);
}
// else if([component isMemberOfClass:[AstMissleLauncherComponent class]])
// {
// AstMissleLauncher* missleLauncher = [[AstMissleLauncher alloc]initWithSession:self.session];
// [self addNode:missleLauncher.rootNode];
// [missleLauncher setComponent:(AstMissleLauncherComponent*)component];
// }
}
}
示例10: joinToWorld
void Monster::joinToWorld(Node* parent)
{
Sprite* sp = Sprite::createWithSpriteFrameName(m_sModelPath.asString().c_str());
/* 创建刚体 */
PhysicsBody* body = PhysicsBody::createBox(sp->getContentSize());
body->setCategoryBitmask(1); // 0001
body->setCollisionBitmask(1); // 0001
body->setContactTestBitmask(1); // 0001
/* 精灵居中 */
sp->setPosition(Point(sp->getContentSize().width * 0.5f, sp->getContentSize().height * 0.5f));
/* 精灵作为Monster的表现,添加到Monster身上 */
this->addChild(sp);
/* 设置怪物Tag类型 */
this->setTag(ObjectTag_Monster);
/* 精灵作为Monster的表现,Monster本身没有大小,所以要设置一下大小 */
this->setContentSize(sp->getContentSize());
/* 刚体添加到Monster本身,而不是精灵身上 */
this->setPhysicsBody(body);
/* 设置坐标 */
this->setPosition(Point(getiPosX(), getiPosY()));
/* Monster加入到物理世界 */
parent->addChild(this);
}
示例11: init
bool LandSprite::init()
{
if (!Sprite::init())
{
return false;
}
Size visiableSize = Director::getInstance()->getVisibleSize();
Vec2 visiableOrigin = Director::getInstance()->getVisibleOrigin();
Sprite * landSprite1 = Sprite::create("assets/land.png");
landSprite1->setAnchorPoint(Vec2(0, 0));
landSprite1->setPosition(Vec2(visiableOrigin.x, visiableOrigin.y));
landSprite1->setScaleX(visiableSize.width / landSprite1->getContentSize().width / 2);
Sprite * landSprite2 = Sprite::create("assets/land.png");
landSprite2->setAnchorPoint(Vec2(0, 0));
landSprite2->setPosition(Vec2(visiableOrigin.x + visiableSize.width / 2, visiableOrigin.y));
landSprite2->setScaleX(visiableSize.width / landSprite2->getContentSize().width / 2);
Sprite * landSprite3 = Sprite::create("assets/land.png");
landSprite3->setAnchorPoint(Vec2(0, 0));
landSprite3->setPosition(Vec2(visiableOrigin.x + visiableSize.width, visiableOrigin.y));
landSprite3->setScaleX(visiableSize.width / landSprite3->getContentSize().width / 2);
Sprite * landSprite4 = Sprite::create("assets/land.png");
landSprite4->setAnchorPoint(Vec2(0, 0));
landSprite4->setPosition(Vec2(visiableOrigin.x + visiableSize.width * 1.5, visiableOrigin.y));
landSprite4->setScaleX(visiableSize.width / landSprite4->getContentSize().width / 2);
Node * landAnimNode = Node::create(); // node hold the land animation
landAnimNode->addChild(landSprite1);
landAnimNode->addChild(landSprite2);
landAnimNode->addChild(landSprite3);
landAnimNode->addChild(landSprite4);
MoveBy * landForward = MoveBy::create(5, Vec2(-visiableSize.width, 0));
MoveBy * landBackward = MoveBy::create(0.001, Vec2(visiableSize.width, 0));
Sequence * moveSeq = Sequence::create(landForward, 0.001, landBackward,NULL);
landSprite1->runAction(RepeatForever::create(moveSeq));
landSprite2->runAction(RepeatForever::create(moveSeq->clone()));
landSprite3->runAction(RepeatForever::create(moveSeq->clone()));
landSprite4->runAction(RepeatForever::create(moveSeq->clone()));
this->addChild(landAnimNode);
this->setAnchorPoint(Vec2(0, 0));
this->setContentSize(Size(visiableSize.width, landSprite1->getContentSize().height));
PhysicsBody * landPhysicsBody = PhysicsBody::createBox(Size(visiableSize.width, landSprite1->getContentSize().height), PhysicsMaterial(1, 1, 0));
landPhysicsBody->setGravityEnable(false);
landPhysicsBody->setDynamic(false);
landPhysicsBody->setContactTestBitmask(1);
landPhysicsBody->setCollisionBitmask(2);
this->setPhysicsBody(landPhysicsBody);
return true;
}
示例12: init
bool Rock::init()
{
if (!Sprite::initWithFile("rock.png"))
{
return false;
}
PhysicsBody* rockBody = PhysicsBody::createBox(this->getContentSize(), PhysicsMaterial(DEFAULT_ROCK_MATERIAL));
rockBody->setDynamic(false);
rockBody->setContactTestBitmask(ROCK_CONTACT_MASK);
rockBody->setCategoryBitmask(ROCK_CATEGORY);
rockBody->setCollisionBitmask(ROCK_COLLISION_MASK);
rockBody->setGravityEnable(false);
this->setPhysicsBody(rockBody);
return true;
}
示例13: addBallObstacle
/*
auto ball = Sprite::create("Ball.png");
PhysicsBody *ballbody = PhysicsBody::create();
ballbody->addShape(PhysicsShapeCircle::create(BIRD_RADIUS+5));
ballbody->setCategoryBitmask(ColliderTypeBird);
ballbody->setCollisionBitmask(ColliderTypeLand | ColliderTypePip);
ballbody->setContactTestBitmask(1);
ballbody->setDynamic(true);
ballbody->setLinearDamping(0.0f);
ballbody->setGravityEnable(true);
ball->setPhysicsBody(ballbody);
auto visibleSize = Director::getInstance()->getVisibleSize();
ball->setPosition(bird->getPositionX()+2*20,visibleSize.height);
addChild(ball);
*/
void GameLayer::addBallObstacle(float dt)
{
auto ball = Sprite::create("Ball.png");
PhysicsBody *ballbody = PhysicsBody::create();
ballbody->addShape(PhysicsShapeCircle::create(BIRD_RADIUS+5));
ballbody->setCategoryBitmask(ColliderTypeBall);
ballbody->setCollisionBitmask(ColliderTypeLand | ColliderTypePip | ColliderTypeBird | ColliderTypeBall);
ballbody->setContactTestBitmask(ColliderTypeBird);
ballbody->setDynamic(true);
ballbody->setLinearDamping(0.0f);
ballbody->setGravityEnable(true);
ball->setPhysicsBody(ballbody);
auto visibleSize = Director::getInstance()->getVisibleSize();
ball->setPosition(bird->getPositionX()+2*20,visibleSize.height);
addChild(ball);
}
示例14: CSpikes
CSpikes :: CSpikes(cocos2d::Layer* layer,const float posx,const float posy)
{
x = posx; y = posy;
m_Sprite = cocos2d::Sprite::create("CloseNormal.png");
//m_Sprite->Sprite::setTexture("CloseNormal.png");
m_Sprite->setScale(10.0f);
m_Sprite->Sprite::setPosition(Point(x,y));
const Size size = Size(m_Sprite->getContentSize().width, m_Sprite->getContentSize().width);
PhysicsBody* body = PhysicsBody::createBox(size);
body->setCollisionBitmask(2);
body->setContactTestBitmask(true);
body->setDynamic(false);
m_Sprite->setPhysicsBody(body);
Render(x,y);
layer->addChild(m_Sprite,0);
thelayer = layer;
}
示例15: init
void MonsterPart::init(Monster * _parent, cocos2d::Layer * layer, cocos2d::Vec2 _pos , std::string spriteName, float _sInterval , int zLayer , bool ifPhysics , BulletType _bulletType)
{
// init parameter
if (_parent != NULL)
{
setPartent(_parent);
}else
parent = NULL;
shootInterval = _sInterval;
this->bulletType = _bulletType;
// set up the sprite
pos = _pos;
sprite = Sprite::create(spriteName);
sprite->setScale(0.5);
if (parent != NULL)
{
sprite->setPosition(parent->getRelatedPos(pos));
sprite->setColor(parent->color);
}
layer->addChild(sprite, zLayer);
// if (ifPhysics)
{
// 1
auto monsterSize = sprite->getContentSize();
PhysicsBody* body = PhysicsBody::createBox(Size(monsterSize.width , monsterSize.height),PhysicsMaterial(0.1f, 1.0f, 0.0f));
// 2
body->setDynamic(true);
// 3
body->setCategoryBitmask(PhysicsCategory::Part);
body->setCollisionBitmask((int)PhysicsCategory::None);
body->setContactTestBitmask((int)PhysicsCategory::MonsterA);
UserData* data = new UserData();
data->part = this;
sprite->setUserData((void*)data);
sprite->setPhysicsBody(body);
}
}