本文整理汇总了C++中PhysicsBody::getNode方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::getNode方法的具体用法?C++ PhysicsBody::getNode怎么用?C++ PhysicsBody::getNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsBody
的用法示例。
在下文中一共展示了PhysicsBody::getNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: onContactBegin
bool HelloWorld::onContactBegin(const PhysicsContact& contact)
{
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
this->removeChild(a->getNode());
this->removeChild(b->getNode());
return true;
}
示例4: 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;
}*/
}
示例5: 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;
}
示例6: onContactBegin
bool HelloWorld::onContactBegin(cocos2d::PhysicsContact &contact) {
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
if ((1 == a->getCollisionBitmask() && 2 == b->getCollisionBitmask()) || (2 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())) {
auto spriteA = (Sprite*)a->getNode();
auto spriteB = (Sprite*)b->getNode();
if (2 == b->getCollisionBitmask()) {
this->removeChild(spriteB, true);
score++;
} else if (2 == a->getCollisionBitmask()) {
this->removeChild(spriteA, true);
score++;
}
}
return true;
}
示例7: 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;
}
示例8: 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;
}
示例9: onContactBegin
bool GameScene::onContactBegin(cocos2d::PhysicsContact & contact)
{
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
if ((BALL_COLLISION_BITMASK == a->getCollisionBitmask() && (BRICK_COLLISION_BITMASK) == b->getCollisionBitmask()) ||
(BALL_COLLISION_BITMASK == b->getCollisionBitmask() && (BRICK_COLLISION_BITMASK) == a->getCollisionBitmask()))
{
auto bricky = b->getNode();
this->removeChild(bricky);
score++;
__String *tempScore = __String::createWithFormat( "%i", score );
scoreLabel->setString( tempScore->getCString( ) );
if (score == 50)
{
auto scene = GameOverScene::createScene(score);
Director::getInstance()->replaceScene(TransitionFade::create(TRANSITION_TIME, scene));
}
}
return true;
}
示例10: 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;
}
示例11: clipPoly
void FruitCutNinjaScene::clipPoly(PhysicsShapePolygon* shape, Point normal, float distance)
{
PhysicsBody* body = shape->getBody();
int count = shape->getPointsCount();
int pointsCount = 0;
Point* points = new Point[count + 1];
Vector2dVector vcPoints;
vcPoints.clear();
Vector2d v2Point(0, 0);
for (int i=0, j=count-1; i<count; j=i, ++i)
{
Point a = body->local2World(shape->getPoint(j));
float aDist = a.dot(normal) - distance;
if (aDist < 0.0f)
{
points[pointsCount] = a;
++pointsCount;
}
Point b = body->local2World(shape->getPoint(i));
float bDist = b.dot(normal) - distance;
if (aDist*bDist < 0.0f)
{
float t = std::fabs(aDist)/(std::fabs(aDist) + std::fabs(bDist));
Vec2 v2Tmp = a.lerp(b, t);
points[pointsCount] = v2Tmp;
++pointsCount;
}
}
Point center = PhysicsShape::getPolyonCenter(points, pointsCount);
for (int i = 0; i < pointsCount; i++)
{
points[i] = body->world2Local(points[i]);
vcPoints.push_back(Vector2d(points[i].x, points[i].y));
}
PhysicsBody* polyon = PhysicsBody::createPolygon(points, pointsCount);
PRFilledPolygon* pNode = (PRFilledPolygon*)(body->getNode());
std::string sName = pNode->getTextureName();
//auto texture = Director::getInstance()->getTextureCache()->addImage("pineapple.png");
PRFilledPolygon *filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(vcPoints, sName.c_str());
filledPolygon->setPhysicsBody(polyon);
filledPolygon->setPosition(body->getPosition() + normal * -40);
filledPolygon->getPhysicsBody()->setTag(_sliceTag);
filledPolygon->getPhysicsBody()->setGravityEnable(false);
polyon->setVelocity(body->getVelocityAtWorldPoint(center));
polyon->setAngularVelocity(body->getAngularVelocity());
polyon->setTag(_sliceTag);
//polyon->applyImpulse(normal * -100);
addChild(filledPolygon, 80);
/*
CPolygonSprite* pSprite = CPolygonSprite::create();
pSprite->initWithFile("pineapple.png", polyon, false);
pSprite->setPosition(body->getPosition());
polyon->setTag(_sliceTag);
addChild(pSprite);
*/
/*
Node* node = Node::create();
PhysicsBody* polyon = PhysicsBody::createPolygon(points, pointsCount, PHYSICSBODY_MATERIAL_DEFAULT, -center);
node->setPosition(center);
node->setPhysicsBody(polyon);
polyon->setVelocity(body->getVelocityAtWorldPoint(center));
polyon->setAngularVelocity(body->getAngularVelocity());
polyon->setTag(_sliceTag);
addChild(node);
*/
delete[] points;
}
示例12: clipPoly
void CCutScene::clipPoly(PhysicsShapePolygon* shape, Point normal, float distance)
{
PhysicsBody* body = shape->getBody();
int count = shape->getPointsCount();
int pointsCount = 0;
Point* points = new Point[count + 1];
Vector2dVector vcPoints;
vcPoints.clear();
Vector2d v2Point(0, 0);
for (int i=0, j=count-1; i<count; j=i, ++i)
{
Point a = body->local2World(shape->getPoint(j));
float aDist = a.dot(normal) - distance;
if (aDist < 0.0f)
{
points[pointsCount] = a;
++pointsCount;
}
Point b = body->local2World(shape->getPoint(i));
float bDist = b.dot(normal) - distance;
if (aDist*bDist < 0.0f)
{
float t = std::fabs(aDist)/(std::fabs(aDist) + std::fabs(bDist));
Vec2 v2Tmp = a.lerp(b, t);
points[pointsCount] = v2Tmp;
++pointsCount;
}
}
Point center = PhysicsShape::getPolyonCenter(points, pointsCount);
for (int i = 0; i < pointsCount; i++)
{
points[i] = body->world2Local(points[i]);
vcPoints.push_back(Vector2d(points[i].x, points[i].y));
}
PhysicsBody* polyon = PhysicsBody::createPolygon(points, pointsCount);
CFoodCut* pNode = (CFoodCut*)(body->getNode());
std::vector<int> vMaterials;
vMaterials.clear();
vMaterials = pNode->getMaterials();
MATERIAL_ID eId = MI_MAX;
if (vMaterials.size() != 0)
{
eId = (MATERIAL_ID)vMaterials[0];
}
CFoodCut *filledPolygon = CFoodCut::create(eId, vcPoints, pNode->getPanziIndex(), pNode->getTouchedIndex());
filledPolygon->setPhysicsBody(polyon);
int nTmp = rand() % 50 + 50;
int nTmpRotate = rand() % 30 - 60;
filledPolygon->setPosition(body->getPosition());
//filledPolygon->setRotation(filledPolygon->getRotation() + nTmpRotate);
filledPolygon->getPhysicsBody()->setTag(_sliceTag);
filledPolygon->getPhysicsBody()->setGravityEnable(false);
polyon->setVelocity(body->getVelocityAtWorldPoint(center));
//polyon->setAngularVelocity(body->getAngularVelocity());
polyon->setTag(_sliceTag);
float fMass = polyon->getMass();
float fV = 80;
float fImpulse = fMass * fV;
float fTmpX = (float)(Random() % 30) / 100.0f - 0.15f;
float fTmpY = (float)(rand() % 30) / 100.0f - 0.15f;
polyon->applyImpulse((normal + Vec2(fTmpX, fTmpY)) * -fImpulse);
polyon->setLinearDamping(0.8f);
addChild(filledPolygon, 80);
filledPolygon->setBirthTime(getCurTime());
m_vCutFoods.push_back(filledPolygon);
m_nSliceCount ++;
delete[] points;
}
示例13: 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;
}
示例14: onContactSeparate
void WorldLayer::onContactSeparate(cocos2d::PhysicsContact &contact) {
PhysicsBody *aBody = contact.getShapeA()->getBody();
Player *player = (Player *)aBody->getNode();
p1->setCollided(NULL);
std::cout << "contact separate\n" << std::endl;
}
示例15: onContactBegin
//response to contact with obstacle
bool GameScene::onContactBegin(cocos2d::PhysicsContact &contact){
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
//if something colides with something else
if ((BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask()) || (BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()) || (BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && ROCKS_COLLISION_BITMASK == b->getCollisionBitmask()) || (BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && ROCKS_COLLISION_BITMASK == a->getCollisionBitmask()) /*|| (BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask()) || (BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask())*/){
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Hit.mp3");
CCParticleSystemQuad* p = CCParticleSystemQuad::create("burn.plist");
p->setPosition(bird->getPosX(), bird->getPosY());
this->addChild(p);
auto scene = GameOverScene::createScene(score);
Director::getInstance()->replaceScene(TransitionFade::create(TRANSITION_TIME, scene));
//output score on death
// CCLOG("SCORE: %i", score); no need to write to output, score in game
//end bkg music
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
}
else if ((BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && POINT_COLLISION_BITMASK == b->getCollisionBitmask()) || (BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && POINT_COLLISION_BITMASK == a->getCollisionBitmask()))
{
// CCLOG("Point Scored");no longer needed to write to output
if (a->getCollisionBitmask() == POINT_COLLISION_BITMASK)
{
a->getNode()->removeFromParent();
}
else {
b->getNode()->removeFromParent();
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Point.mp3");
score++;
__String *tempScore = __String::createWithFormat("%i", score);
scoreLabel->setString(tempScore->getCString());
}
}
else if ((EDGE_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask()) || (EDGE_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()) || (EDGE_COLLISION_BITMASK == a->getCollisionBitmask() && ROCKS_COLLISION_BITMASK == b->getCollisionBitmask()) || (EDGE_COLLISION_BITMASK == b->getCollisionBitmask() && ROCKS_COLLISION_BITMASK == a->getCollisionBitmask()) || (POINT_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask()) || (POINT_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask())){
//remove sprites as they remove from screen
if (a->getCollisionBitmask() == EDGE_COLLISION_BITMASK){
CCParticleSystemQuad* p = CCParticleSystemQuad::create("debris_2.plist");
p->setPosition(b->getNode()->getPosition());
this->addChild(p);
//if (frstContact == false){
// auto alienSize = Sprite::create("Alien.png");
// CCParticleSystemQuad* p = CCParticleSystemQuad::create("debris.plist");
// p->setPosition(b->getNode()->getPosition() + alienSize->getContentSize() / 2);
// this->addChild(p);
// frstContact = true;
//}
b->getNode()->removeFromParent();
}
else{
CCParticleSystemQuad* p = CCParticleSystemQuad::create("debris_2.plist");
p->setPosition(b->getNode()->getPosition());
this->addChild(p);
//if (frstContact == false){
// auto alienSize = Sprite::create("Alien.png");
// CCParticleSystemQuad* p = CCParticleSystemQuad::create("debris.plist");
// p->setPosition(b->getNode()->getPosition() + alienSize->getContentSize() / 2);
// this->addChild(p);
// frstContact = true;
//}
a->getNode()->removeFromParent();
}
}
return true;
}