本文整理汇总了C++中PhysicsBody::getTag方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::getTag方法的具体用法?C++ PhysicsBody::getTag怎么用?C++ PhysicsBody::getTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsBody
的用法示例。
在下文中一共展示了PhysicsBody::getTag方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hitTest
bool hitTest(PhysicsContact& contact, int mask) {
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
int tagA = a->getTag();
int tagB = b->getTag();
int tag = tagA | tagB;
return (tag & mask) == mask;
}
示例2: switch
/** 碰撞开始事件
* @2015/12/16 11:28
*/
bool Level_1::onCollisionBegin(const cocos2d::PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
PhysicsBody* temp =nullptr;
//log("A:%d B:%d",bodyA->getTag(),bodyB->getTag());
if(bodyA->getTag() == 555555)
{
temp = bodyB;
bodyB = bodyA;
bodyA = temp;
}
if(bodyB->getTag() == 555555)
{
//log("A:%d",bodyA->getTag());
// 100001 物理世界
// 555555 主要车的
// 300001 悬浮的物体
// 400001 第一关的怪物
// 600001 弹簧的物体
if (bodyA->getTag()== 400001)
{
MainCar_R* car =(MainCar_R*)bodyB->getNode()->getParent()->getParent();
//car->removeFromParent();
car->setBodyEnable();
}
switch (bodyA->getTag()) {
case 400001:
log("第一关的怪物");
bodyB->setEnabled(false);
break;
case 300001:
log("悬浮的物体");
break;
case 600001:
log("弹簧的物体");
break;
default:
break;
}
}
return true;
}
示例3: onContactBegin
bool PFMPlayer::onContactBegin(cocos2d::PhysicsContact &contact)
{
if(contact.getShapeA()->getBody() == getPhysicsBody() ||
contact.getShapeB()->getBody() == getPhysicsBody())
{
PhysicsBody* other = contact.getShapeA()->getBody() == getPhysicsBody()?contact.getShapeB()->getBody() : contact.getShapeA()->getBody();
switch (other->getTag()) {
case PFMPhysicsBodyTypeEnemyBullet:
{
PFMBullet* bullet = dynamic_cast<PFMBullet*>(other->getNode());
if(bullet != NULL)
{
health -= bullet->damage;
}
other->getOwner()->removeFromParentAndCleanup(true);
break;
}
case PFMPhysicsBodyTypeEnemy:
other->getOwner()->removeFromParentAndCleanup(true);
break;
default:
break;
}
}
return true;
}
示例4: if
Node *getNodeByTag(PhysicsContact& contact, int tag) {
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
int tagA = a->getTag();
int tagB = b->getTag();
Node *node;
if (tagA == tag)
node = a->getNode();
else if (tagB == tag)
node = b->getNode();
else
node = NULL;
return node;
}
示例5: onContactBegin
bool TankContainer::onContactBegin(PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
if ((bodyA->getTag() == 1) && (bodyB->getTag() == 1)) //tanks
{
CCLOG("Contact 2 tanks");
return true;
}
if ((bodyA->getTag() == 10) && (bodyB->getTag() == 10)) //bullets
{
CCLOG("Contact 2 bullets");
return true;
}
if (((bodyA->getTag() == 1) && (bodyB->getTag() == 10)) || ((bodyB->getTag() == 1) && (bodyA->getTag() == 10)))
{
Tank* tank;
BulletAbstract* bullet;
if (bodyA->getTag() == 1)
{
tank = dynamic_cast<Tank*>(bodyA->getNode());
bullet = dynamic_cast<BulletAbstract*>(bodyB->getNode());
}
else
{
tank = dynamic_cast<Tank*>(bodyB->getNode());
bullet = dynamic_cast<BulletAbstract*>(bodyA->getNode());
}
if (bullet->getLifeTime() >= 1.97)
{
;// return false;
}
CCLOG("Contact bullets and tank");
if (tank)
tank->destroy();
if (bullet)
bullet->destroy();
}
return true;
/*
else
{
bodyA->setVelocity(Vec2(0, 0));
bodyB->setVelocity(Vec2(0, 0));
return true;
}*/
}
示例6: removeBody
void PhysicsWorld::removeBody(int tag)
{
for (Object* obj : *_bodies)
{
PhysicsBody* body = dynamic_cast<PhysicsBody*>(obj);
if (body->getTag() == tag)
{
removeBody(body);
return;
}
}
}
示例7: onCollisionBegin
/** 碰撞开始事件
* @2015/12/28 14:40
*/
bool guaiwu_js::onCollisionBegin(const cocos2d::PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
PhysicsBody* temp =nullptr;
log("弹簧 A:%d B:%d",bodyA->getTag(),bodyB->getTag());
if(bodyA->getTag() == 400001){
temp = bodyB;
bodyB = bodyA;
bodyA = temp;
}
if(bodyB->getTag() == 400001)
{
if (bodyA->getTag() ==400008)
{
//设置怪物 停止移动
isMove =false;
//切换动画吃东西
this->removeFromParent();
}
if (bodyA->getTag() == 400010) {
this->iskeyl = !this->iskeyl;
this->iskeyr = !this->iskeyr;
this->setScaleX(-this->getScaleX());
log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
switch (bodyA->getTag()) {
case 400006:
if (bodyA->getNode() !=nullptr)
{
bodyA->getNode()->removeFromParent();
}
setEat();
break;
case 555555:
//僵死碰到车
guaiwu_js::killcar();
break;
case 600001:
break;
default:
break;
}
}
return true;
}
示例8: log
/** 碰撞开始事件
* @2015/01/19 14:14
*/
bool Level_8::onCollisionBegin(const cocos2d::PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
PhysicsBody* temp =nullptr;
//log("A:%d B:%d",bodyA->getTag(),bodyB->getTag());
if(bodyA->getTag() == 600050)
{
temp = bodyB;
bodyB = bodyA;
bodyA = temp;
}
if(bodyB->getTag() == 600050)
{
if (bodyA->getTag() == 400010) {
log("火碰到冰块了 》》》》》》》》》》》》》");
auto anim_iceo = CSLoader::createTimeline("Node/level_animation/l8_ice.csb");
anim_iceo->gotoFrameAndPlay(0, 70, false);
masklayer->removeFromParent();
root_level->runAction(anim_iceo);
}
}
return false;
}
示例9: onContactBegin
bool GameSceneQuattro::onContactBegin(cocos2d::PhysicsContact &contact)
{
cocos2d::log("GameSceneQuattro::onContactBegin ....... inizio ");
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
PhysicsBody *pallinaBody = nullptr ;
if ( ! (3 == a->getCollisionBitmask() && 3 == b->getCollisionBitmask())){
if ( 3 == a->getCollisionBitmask() )
{
// CCLOG( "GameSceneQuattro::onContactBegin COLLISION HAS OCCURED" );
pallinaBody = contact.getShapeA()->getBody();
}
if ( 3 == b->getCollisionBitmask() )
{
pallinaBody = contact.getShapeB()->getBody();
}
if(pallinaBody){
_emitter->setPosition(pallinaBody->getNode()->getPosition());
_emitter->resetSystem();
_emitter->setDuration(0.5);
//prendo tag
if (12 == pallinaBody->getTag()){
cocos2d::log("GameSceneQuattro::onContactBegin colpita pallina 2 ");
//deve variare la y
// pallinaBody->applyForce( Vect(-50, -220) );
pallinaBody->setVelocity(Vec2(randomValueTra(900,900),
randomValueTra(0,500)));
}
if (13 == pallinaBody->getTag()){
cocos2d::log("GameSceneQuattro::onContactBegin colpita pallina 3 ");
pallinaBody->setVelocity(Vec2(randomValueTra(900,1900),
randomValueTra(0,800)));
}
if (14 == pallinaBody->getTag()){
cocos2d::log("GameSceneQuattro::onContactBegin colpita pallina 4 ");
pallinaBody->setVelocity(Vec2(randomValueTra(900,1900),
randomValueTra(0,800)));
}
if (15 == pallinaBody->getTag()){
cocos2d::log("GameSceneQuattro::onContactBegin colpita pallina 5 ");
pallinaBody->setVelocity(Vec2(randomValueTra(900,1900),
randomValueTra(-400,800)));
}
}
}
if (PIETRA_TAG == a->getTag()){
// cocos2d::log("GameSceneQuattro::onContactBegin ....... 1 ");
a-> getNode()->stopAllActions();
a-> getNode()->setVisible(false);
a->removeFromWorld();
//a->setEnable(false); // a->applyForce( Vect(100, 78) );
}
if (PIETRA_TAG == b->getTag() ){
// cocos2d::log("GameSceneQuattro::onContactBegin ....... 2 ");
b-> getNode()->stopAllActions();
b-> getNode()->setVisible(false);
b->removeFromWorld();
// b->setEnable(false);
// b->applyForce( Vect(100, 78) );
}
CCLOG("Forse megio cosi recupero i tag e poi faccio tutto" );
auto sp = (Sprite*)contact.getShapeA()->getBody()->getNode();
int tag = sp->getTag();
CCLOG("onContactBegin tag di A : %d", tag);
auto spb = (Sprite*)contact.getShapeA()->getBody()->getNode();
int tagb = spb->getTag();
CCLOG("onContactBegin tag di B : %d", tagb);
return true;
}