本文整理汇总了C++中PhysicsContact类的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsContact类的具体用法?C++ PhysicsContact怎么用?C++ PhysicsContact使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhysicsContact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: collisionBeginCallback
int PhysicsWorld::collisionBeginCallback(PhysicsContact& contact)
{
bool ret = true;
PhysicsShape* shapeA = contact.getShapeA();
PhysicsShape* shapeB = contact.getShapeB();
PhysicsBody* bodyA = shapeA->getBody();
PhysicsBody* bodyB = shapeB->getBody();
std::vector<PhysicsJoint*> jointsA = bodyA->getJoints();
// check the joint is collision enable or not
for (PhysicsJoint* joint : jointsA)
{
if (std::find(_joints.begin(), _joints.end(), joint) == _joints.end())
{
continue;
}
if (!joint->isCollisionEnabled())
{
PhysicsBody* body = joint->getBodyA() == bodyA ? joint->getBodyB() : joint->getBodyA();
if (body == bodyB)
{
contact.setNotificationEnable(false);
return false;
}
}
}
// bitmask check
if ((shapeA->getCategoryBitmask() & shapeB->getContactTestBitmask()) == 0
|| (shapeA->getContactTestBitmask() & shapeB->getCategoryBitmask()) == 0)
{
contact.setNotificationEnable(false);
}
if (shapeA->getGroup() != 0 && shapeA->getGroup() == shapeB->getGroup())
{
ret = shapeA->getGroup() > 0;
}
else
{
if ((shapeA->getCategoryBitmask() & shapeB->getCollisionBitmask()) == 0
|| (shapeB->getCategoryBitmask() & shapeA->getCollisionBitmask()) == 0)
{
ret = false;
}
}
if (contact.isNotificationEnabled())
{
contact.setEventCode(PhysicsContact::EventCode::BEGIN);
contact.setWorld(this);
_scene->getEventDispatcher()->dispatchEvent(&contact);
}
return ret ? contact.resetResult() : false;
}
示例2: onContactBegan
bool Demo::onContactBegan(PhysicsContact& contact)
{
auto m_action = FadeOut::create(0.3f);
auto sp1 = (Sprite*)contact.getShapeA()->getBody()->getNode();
auto sp2 = (Sprite*)contact.getShapeB()->getBody()->getNode();
if (sp1->getTag() == 1 && sp2->getTag() == 2) {
sp1->runAction(m_action);
testParticleFireworks();
}
else if (sp1->getTag() == 2 && sp2->getTag() == 1) {
sp2->runAction(m_action);
testParticleFireworks();
}
return true;
}
示例3: onContactPostSolve
void GameScene::onContactPostSolve(PhysicsContact &contact, const PhysicsContactPostSolve &solve)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
if (bodyA->getTag() == PLAYER && bodyB->getTag() == TILE)
{
bodyA->setVelocity(Vec2(bodyA->getVelocity().x * RESTITUTION, bodyA->getVelocity().y * RESTITUTION));
}
if (bodyB->getTag() == PLAYER && bodyA->getTag() == TILE)
{
bodyB->setVelocity(Vec2(bodyB->getVelocity().x * RESTITUTION, bodyB->getVelocity().y * RESTITUTION));
}
}
示例4: onContactSeparate
bool PassGateComponent::onContactSeparate(PhysicsContact& contact)
{
if ((contact.getShapeA()->getCollisionBitmask() == PLAYER_ID) && (contact.getShapeB()->getCollisionBitmask() == PASSGATE_AREA_ID))
{
if ((_collisionPointX != 0) && (abs(_collisionPointX - contact.getShapeA()->getBody()->getPosition().x) > GATE_WIDTH-5))
{
// change 'Y' coordinate of the 'gate' main point
auto action = MoveTo::create(GATE_ACTION_SPEED, Point(_visibleSize.width / 2, nextPosY()));
_mainNode->runAction(action);
}
_collisionPointX = contact.getShapeA()->getBody()->getPosition().x;
}
return false;
}
示例5: cpArbiterIgnore
int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact)
{
if (!contact.isNotificationEnabled())
{
cpArbiterIgnore(static_cast<cpArbiter*>(contact._contactInfo));
return true;
}
contact.setEventCode(PhysicsContact::EventCode::PRESOLVE);
contact.setWorld(this);
EventCustom event(PHYSICSCONTACT_EVENT_NAME);
event.setUserData(&contact);
_scene->getEventDispatcher()->dispatchEvent(&event);
return contact.resetResult();
}
示例6: onContactBegin
bool PlayerComponent::onContactBegin(PhysicsContact& contact)
{
if (!is_endGame)
{
PhysicsBody *a = contact.getShapeB()->getBody();
if ((a->getCollisionBitmask() == OBSTACLE_ID) || (a->getCollisionBitmask() == SPIKESBORDER_ID))
{
is_onTouch = false;
is_fall = false;
is_endGame = true;
// display 'dialog box'
this->getOwner()->addChild(MyDialogBox::create(
{
Label::create("Your Score:", "Calibri", 30),
Label::create(StringUtils::toString(((ScoreCounterComponent*)this->getOwner()->getComponent(SCORECOUNTER_NAME))->getScore()), "Calibri", 120)
},
{
DialogBoxButton("TRY AGAIN", TextHAlignment::LEFT, CC_CALLBACK_1(GameScene::goToGameScene, ((GameScene*)this->getOwner()))),
DialogBoxButton("BACK TO\n MAIN MENU", TextHAlignment::RIGHT, CC_CALLBACK_1(GameScene::goToMainMenuScene, ((GameScene*)this->getOwner())))
}
), 10);
}
}
return false;
}
示例7: onContactBegin
bool ObjectLayer::onContactBegin(PhysicsContact& contact)
{
auto objectA = static_cast<custom::Object*>(contact.getShapeA()->getBody()->getNode());
auto objectB = static_cast<custom::Object*>(contact.getShapeB()->getBody()->getNode());
if (!objectA || !objectB || !objectA->GetOwner() || !objectB->GetOwner())
{
return false;
}
if (objectA->GetOwner()->GetType() != objectB->GetOwner()->GetType())
{
objectA->Damaged(objectB->GetDefInfo().m_Damage);
objectB->Damaged(objectA->GetDefInfo().m_Damage);
}
return true;
}
示例8: onContactBegin
bool Balloon::onContactBegin(PhysicsContact& contact)
{
auto balloon = static_cast<Balloon*>(contact.getCurrentTarget());
//if (obj1->getTag() != obj2->getTag())
//{
//obj1->removeFromParent();
/*
Event e = contact;
auto balloon = static_cast<Balloon*>(e.getCurrentTarget());
contact.
balloon->setVisible(false);*/
//}
//int tag = s->getTag();
//CCLog("Contact tag: %d", obj1->getTag());
//CCLog("Contact tag: %d", obj2->getTag());
//this->removeFromParent();
//this->setVisible(false);
//HelloWorld::removeBalloon(this);
return true;
}
示例9: if
void GameScene_Box2D::onContactPostSolve(PhysicsContact& contact, const PhysicsContactPostSolve& solve)
{
auto node1 = contact.getShapeA()->getBody()->getNode();
auto node2 = contact.getShapeB()->getBody()->getNode();
if (node1->getTag()== spriteType::kFloor && node2->getTag()== spriteType::kBall) {
BallSprite *ball = (BallSprite *)node2;
bool ball_state_none = (ball->getBallContState() == BallSprite::ballContactState::kNone);
if (ball_state_none) {
ball->setBallContState(BallSprite::ballContactState::kFloorContact);
}
}
else if (node2->getTag()== spriteType::kFloor && node1->getTag()== spriteType::kBall) {
BallSprite *ball = (BallSprite *)node1;
bool ball_state_none = (ball->getBallContState() == BallSprite::ballContactState::kNone);
ball->setBallContState(BallSprite::ballContactState::kFloorContact);
if (ball_state_none) {
ball->setBallContState(BallSprite::ballContactState::kFloorContact);
}
}
else if (node2->getTag()== spriteType::kBall && node1->getTag()== spriteType::kBall) {
BallSprite *ball1 = (BallSprite *)node1;
BallSprite *ball2 = (BallSprite *)node2;
bool ball1_state_floor = (ball1->getBallContState() == BallSprite::ballContactState::kFloorContact);
bool ball2_state_floor = (ball2->getBallContState() == BallSprite::ballContactState::kFloorContact);
bool ball1_state_none = (ball1->getBallContState() == BallSprite::ballContactState::kNone);
bool ball2_state_none = (ball2->getBallContState() == BallSprite::ballContactState::kNone);
bool ball1_state_second = (ball1->getBallContState() == BallSprite::ballContactState::kSecondContact);
bool ball2_state_second = (ball2->getBallContState() == BallSprite::ballContactState::kSecondContact);
if (ball1_state_none || ball2_state_floor) {
ball1->setBallContState(BallSprite::ballContactState::kSecondContact);
}
else if (ball1_state_floor || ball2_state_none) {
ball2->setBallContState(BallSprite::ballContactState::kSecondContact);
}
else if (ball1_state_none || ball2_state_second) {
ball1->setBallContState(BallSprite::ballContactState::kSecondContact);
}
else if (ball2_state_none || ball1_state_second) {
ball2->setBallContState(BallSprite::ballContactState::kSecondContact);
}
}
}
示例10: onContactBegan
bool GamePlay::onContactBegan(PhysicsContact &contact) {
auto nodeA = contact.getShapeA()->getBody()->getNode();
auto nodeB = contact.getShapeB()->getBody()->getNode();
auto bang = Sprite::create("HelloWorld.png");
bang->setScale(0.03);
bang->setPosition(nodeA->getPosition());
this->addChild(bang);
auto actionMove = MoveTo::create(1, nodeA->getPosition());
auto actionRemove = RemoveSelf::create();
bang->runAction(Sequence::create(actionMove,actionRemove, nullptr));
nodeA->removeFromParent();
nodeB->removeFromParent();
return true;
}
示例11: onContactBegin
bool HelloWorld::onContactBegin(PhysicsContact& contact){
//接触开始
auto a = contact.getShapeA()->getTag();
auto b = contact.getShapeB()->getTag();
if ((a*b) == PLAYER_TAG * EDGE_TAG) {
isContact = true;
isPressedW = false;
jumped = false;
}
else if ((a*b) == PLAYER_TAG*ENEMY_TAG_ZERO){
player1->contactNumber++;
}
auto temp = String::createWithFormat("%d", player1->contactNumber);
log(temp->getCString());
log("onContactBegin");
return true;
}
示例12: onContactBegin
bool WorldLayer::onContactBegin(PhysicsContact& contact) {
PhysicsBody *aBody = contact.getShapeA()->getBody();
PhysicsBody *bBody =contact.getShapeB()->getBody();
Player *player = NULL;
Entity *object = NULL;
if(aBody->getNode()->getTag() == 1) {
player = (Player *)aBody->getNode();
object = (Entity *)bBody->getNode();
player->setCollided(object);
return true;
} else if(bBody->getNode()->getTag() == 1) {
player = (Player *)bBody->getNode();
object = (Entity *)aBody->getNode();
player->setCollided(object);
return true;
}
return false;
}
示例13: onContactSeperate
void MainScene::onContactSeperate(const PhysicsContact& contact)
{
auto playerA = (Player*)contact.getShapeA()->getBody()->getNode();
auto playerB = (Player*)contact.getShapeB()->getBody()->getNode();
auto typeA = playerA->getPlayerType();
auto typeB = playerB->getPlayerType();
if (typeA == Player::PlayerType::PLAYER)
{
log("leave enemy!");
playerB->setCanAttack(false);
playerA->removeAttacker(playerB);
}
if (typeB == Player::PlayerType::PLAYER)
{
log("leave enemy!");
playerA->setCanAttack(false);
playerB->removeAttacker(playerA);
}
}
示例14: onContactSeperate
void MainScene::onContactSeperate(const PhysicsContact& contact)
{
auto playerA = (Player*)contact.getShapeA()->getBody()->getNode();
auto playerB = (Player*)contact.getShapeB()->getBody()->getNode();
auto typeA = playerA->getPlayerType();
auto typeB = playerB->getPlayerType();
if(typeA == Player::PlayerType::PLAYER)
{
// only one player so ShapeB must belong to an enemy
log("leave enemy!");
playerB->setCanAttack(false);
}
if(typeB == Player::PlayerType::PLAYER)
{
// only one player so ShapeA must belong to an enemy
log("leave enemy!");
playerA->setCanAttack(false);
}
}
示例15: onContactBegin
bool CBullet::onContactBegin(PhysicsContact &contact)
{
auto nodeA = contact.getShapeA()->getBody()->getNode();
auto nodeB = contact.getShapeB()->getBody()->getNode();
if (nodeA && nodeB)
{
//bullet collision with enemy objects and wall objects
if (nodeA->getTag() == BULLET_TAG && nodeB->getTag() == ENEMY_TAG)
{
nodeA->removeFromParentAndCleanup(true);
}
else if (nodeB->getTag() == BULLET_TAG && nodeA->getTag() == ENEMY_TAG)
{
nodeB->removeFromParentAndCleanup(true);
}
}
return true;
}