本文整理汇总了C++中cocos2d::PhysicsContact::getShapeA方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsContact::getShapeA方法的具体用法?C++ PhysicsContact::getShapeA怎么用?C++ PhysicsContact::getShapeA使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocos2d::PhysicsContact
的用法示例。
在下文中一共展示了PhysicsContact::getShapeA方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: switchMoveActionAfter
bool ContactManager::switchMoveActionAfter(const cocos2d::PhysicsContact &contact){
int body_tag = 0;
//找到碰撞物体
if(contact.getShapeA()->getBody()->getNode()->getTag()==PROTAGONIST_TAG){
node_Pro = contact.getShapeA()->getBody()->getNode();
node_else =contact.getShapeB()->getBody()->getNode();
body_tag = node_else->getTag();
}else{
node_Pro = contact.getShapeB()->getBody()->getNode();
node_else = contact.getShapeA()->getBody()->getNode();
body_tag = node_else->getTag();
}
switch((body_tag/1000)*1000){
case SECTION_TAG:{
ContactManager::onContactSeparatePro_Section();
break;
}
}
return false;
}
示例3: onContactBegin
bool CGameLayer::onContactBegin(cocos2d::PhysicsContact &contact)
{
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
contact.getShapeA()->getTag();
if (((MASK_BALL == a->getCollisionBitmask()) &&
(BORDER_CONTACT_BITMASK == b->getCollisionBitmask())) ||
((MASK_BALL == b->getCollisionBitmask()) &&
(BORDER_CONTACT_BITMASK == a->getCollisionBitmask())))
{
if (m_startBallMovement)
{
--g_gameState->m_life;
this->removeChildByTag(TAG_BALL, true);
m_ball.erase(m_ball.begin());
CBall *_ball = new (std::nothrow) CBall();
_ball->init(this, g_gameState->m_acc * g_gameState->m_level, m_player->GetPosition());
//this->addChild(_ball);
m_ball.push_back(_ball);
m_startBallMovement = false;
}
return true;
}
if (((MASK_BALL == a->getCollisionBitmask()) &&
(MASK_BLOCK == b->getCollisionBitmask())) ||
((MASK_BALL == b->getCollisionBitmask()) &&
(MASK_BLOCK == a->getCollisionBitmask())))
{
int pTag;
if ((MASK_BALL == a->getCollisionBitmask()) && (MASK_BLOCK == b->getCollisionBitmask()))
{
pTag = b->getNode()->getTag();
}
else
{
pTag = a->getNode()->getTag();
}
int i = 0;
for (auto it = m_blocks.begin(); it != m_blocks.end(); ++it)
{
if (pTag == m_blocks[i]->getTag())
{
playerScore();
m_blocks[i]->del(this);
it = m_blocks.erase(it);
--it;
}
++i;
}
return true;
}
else if ((a->getCollisionBitmask() == MASK_BALL && MASK_RACKET == b->getCollisionBitmask()) ||
(b->getCollisionBitmask() == MASK_BALL && MASK_RACKET == a->getCollisionBitmask()))
{
return true;
}
return false;
}
示例4: onContactBegin
bool GameLayer::onContactBegin(cocos2d::PhysicsContact &contact)
{
log("2222");
if ((contact.getShapeA()->getBody()->getCategoryBitmask() & kMaskBall) == kMaskBall)
{
//ball do something
}
if ((contact.getShapeB()->getBody()->getCategoryBitmask() & kMaskBall) == kMaskBall)
{
//ball do something
}
if ((contact.getShapeA()->getBody()->getCategoryBitmask() & kMaskPlayer) == kMaskPlayer)
{
//player do something
}
if ((contact.getShapeB()->getBody()->getCategoryBitmask() & kMaskPlayer) == kMaskPlayer)
{
//player do something
}
// auto nodeA = (Sprite*)contact.getShapeA()->getBody()->getNode();
// auto nodeB = (Sprite*)contact.getShapeB()->getBody()->getNode();
//
// if (nodeA == nullptr || nodeB == nullptr)
// {
//
// return false;
// }
return true;
}
示例5: onContactBegin
bool GameScene::onContactBegin( cocos2d::PhysicsContact &contact )
{
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
if ( ( BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask() ) ||
( BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask() ) )
{
CCLOG("a :%i", a->getCollisionBitmask());
CCLOG("b: %i", b->getCollisionBitmask() );
CCLOG("Score: %i", score );
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Hit.mp3");
auto scene = GameOverScene::createScene( score );
Director::getInstance()->replaceScene(TransitionFade::create( TRANSITION_TIME, scene ) );
}
else if ( ( BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && POINT_COLLISION_BITMASK == b->getCollisionBitmask() ) ||
( BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && POINT_COLLISION_BITMASK == a->getCollisionBitmask() ) )
{
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Point.mp3");
score++;
__String *tempScore = __String::createWithFormat( "%i", score );
scoreLabel->setString( tempScore->getCString() );
}
return true;
}
示例6: onContactBegin
bool BombMissile::onContactBegin(cocos2d::PhysicsContact& contact)
{
//한 번만 데미지 입히게 하기 위한 용도. 뎀 드가고 나면 그림만 보임.
//실제 미사일 삭제 시점은 그래픽 사라지는 시점.
m_IsPhysics = false;
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = (BaseComponent*)bodyA->getNode();
auto componentB = (BaseComponent*)bodyB->getNode();
BaseComponent* enemyComponent;
bool isComponentA = true;
if (componentA->getType() == getType())
{
enemyComponent = componentB;
isComponentA = true;
}
else
{
enemyComponent = componentA;
isComponentA = false;
}
GET_SOUND_MANAGER()->createSound(SoundManager::MONSTERHIT, false, getPosition());
GET_EFFECT_MANAGER()->createEffect(ET_PUNCH_MISSILE, enemyComponent->getPosition())->enter();
return false;
}
示例7: onContactBegin
bool GameScene::onContactBegin(cocos2d::PhysicsContact &contact) {
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
if ( (SNAKE_COLLISION_BITMASK == a->getCollisionBitmask() && FOOD_COLLISION_BITMASK == b->getCollisionBitmask()) ||
(SNAKE_COLLISION_BITMASK == b->getCollisionBitmask() && FOOD_COLLISION_BITMASK == a->getCollisionBitmask()) ) {
srand(time(NULL));
auto random = rand() % 370 + 30;
auto random2 = rand() % 270 + 30;
auto moveTo = MoveTo::create(0, Vec2(random, random2));
food->runAction(moveTo);
int tempX = snakeParts.back()->getPositionX();
int tempY = snakeParts.back()->getPositionY();
Sprite* tempSprite = Sprite::create("snake.png");
switch (direction) {
case LEFT:
tempSprite->setPosition(tempX + 10, tempY);
break;
case RIGHT:
tempSprite->setPosition(tempX - 10, tempY);
break;
case UP:
tempSprite->setPosition(tempX, tempY + 10);
break;
case DOWN:
tempSprite->setPosition(tempX, tempY - 10);
break;
}
this->addChild(tempSprite);
snakeParts.push_back(tempSprite);
}
return true;
}
示例8: onContactBegin
bool MonsterDevil::onContactBegin(cocos2d::PhysicsContact& contact)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = (BaseComponent*)bodyA->getNode();
auto componentB = (BaseComponent*)bodyB->getNode();
BaseComponent* enemyComponent;
bool isComponentA = true;
//어떤것 끼리 부딪혔는지는 안가르쳐주기 때문에
//여기서 어느쪽이 monsterDevil인지 밝혀낸다.
if (componentA->getType() == getType())
{
enemyComponent = componentB;
isComponentA = true;
}
else
{
enemyComponent = componentA;
isComponentA = false;
}
//FLOOR 충돌 무시
if (enemyComponent->getType() == OT_FLOOR)
{
return false;
}
//미사일이랑 충돌 처리
if (enemyComponent->getPhysicsBody()->getCategoryBitmask() == PHYC_MISSILE)
{
Missile* missile = static_cast<Missile*>(enemyComponent);
//수류탄은 뎀 안 입음
if (missile->getType() == OT_MISSILE_GRENADE)
{
return false;
}
//몹이 쏜 건 안 맞음.
if (!missile->isPlayerMissile())
{
return false;
}
float damage = missile->getDamage();
m_Info.m_CurrentHp -= damage * 100 / (100 + m_Info.m_DefensivePower);
//사망
if (m_Info.m_CurrentHp <= 0)
{
m_IsDead = true;
}
}
return true;
}
示例9: onContactBegin
bool LevelThree::onContactBegin(cocos2d::PhysicsContact &contact)
{
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
//On contact between player and any enemy, spike, or laser. Kill player. Check Lives. Run reset/Game Over.
return true;
}
示例10: ContactDetect
static bool ContactDetect(cocos2d::PhysicsContact & contact, cocos2d::Layer * layer, int * score)
{
cocos2d::Node * nodeA = contact.getShapeA()->getBody()->getNode();
cocos2d::Node * nodeB = contact.getShapeB()->getBody()->getNode();
if (nodeA && nodeB)
{
int maskA = nodeA->getPhysicsBody()->getContactTestBitmask();
int maskB = nodeB->getPhysicsBody()->getContactTestBitmask();
switch (maskA | maskB)
{
case 0b0101 :
{
// EnemyFighter with Fighter
Fighter * fighter = ((maskA == 0b0100) ? (Fighter *)nodeA : (Fighter *)nodeB);
EnemyFighter * enemy = ((maskA == 0b0001) ? (EnemyFighter *)nodeA : (EnemyFighter *)nodeB);
FighterWithEnemy(fighter, enemy, score);
break;
}
case 0b0110 :
{
// EnemyBullet with Fighter
Fighter * fighter;
EnemyBullet * bullet;
if (maskA == 0b0100)
{
fighter = dynamic_cast<Fighter *>(nodeA);
bullet = dynamic_cast<EnemyBullet *>(nodeB);
}
else
{
fighter = dynamic_cast<Fighter *>(nodeB);
bullet = dynamic_cast<EnemyBullet *>(nodeA);
}
FighterWithBullet(fighter, bullet, score);
break;
}
case 0b1001 :
{
// Bullet with EnemyFighter
EnemyFighter * enemy = ((maskA == 0b0001) ? (EnemyFighter *)nodeA : (EnemyFighter *)nodeB);
Bullet * bullet = ((maskA == 0b1000) ? (Bullet *)nodeA : (Bullet *)nodeB);
EnemyWithBullet(enemy, bullet, layer, score);
break;
}
default:
break;
}
}
return false;
}
示例11: switchMoveAction
bool ContactManager::switchMoveAction(const cocos2d::PhysicsContact &contact){
int body_tag = 0;
//找到碰撞物体
if(contact.getShapeA()->getBody()->getNode()->getTag()==PROTAGONIST_TAG){
node_Pro = contact.getShapeA()->getBody()->getNode();
node_else =contact.getShapeB()->getBody()->getNode();
body_tag = node_else->getTag();
}else{
node_Pro = contact.getShapeB()->getBody()->getNode();
node_else = contact.getShapeA()->getBody()->getNode();
body_tag = node_else->getTag();
}
switch((body_tag/1000)*1000){
case SECTION_TAG:{
ContactManager::onContactBeginPro_Section();
break;
}
case JAILER_TAG:{
ContactManager::onContactBeginPro_Jailer();
break;
}
case MOUSE_TAG:{
ContactManager::onContactBeginPro_Mouse();
break;
}
case COIN_TAG:{
ContactManager::onContactBeginPro_Coin();
break;
}
case WALL_TAG:{
ContactManager::onContactBeginPro_Wall();
break;
}
case SECTION_END_TAG:{
ContactManager::onContactBeginPro_End();
break;
}
}
return false;
}
示例12: onContactSeperate
void LevelThree::onContactSeperate(cocos2d::PhysicsContact &contact)
{
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
if (1 == a->getCollisionBitmask() || 1 == b->getCollisionBitmask())
{
}
}
示例13: onContactBegin
bool GameLayer::onContactBegin(cocos2d::PhysicsContact& contact)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = static_cast<BaseComponent*>( bodyA->getNode() );
auto componentB = static_cast<BaseComponent*>( bodyB->getNode() );
bool resA = componentA->onContactBegin(contact);
bool resB = componentB->onContactBegin(contact);
return resA && resB;
}
示例14: onContactPreSolve
bool LevelThree::onContactPreSolve(cocos2d::PhysicsContact &contact, cocos2d::PhysicsContactPreSolve& solve)
{
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
if (1 == a->getCollisionBitmask() || 1 == b->getCollisionBitmask())
{
solve.setRestitution(0);
}
return true;
}
示例15: 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;
}