本文整理汇总了C++中PhysicsSprite::getTag方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsSprite::getTag方法的具体用法?C++ PhysicsSprite::getTag怎么用?C++ PhysicsSprite::getTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsSprite
的用法示例。
在下文中一共展示了PhysicsSprite::getTag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BeginContact
void GamePhysicsContactListener::BeginContact(b2Contact* contact)
{
// 衝突した双方の物体を取得
b2Body* bodyA = contact->GetFixtureA()->GetBody();
b2Body* bodyB = contact->GetFixtureB()->GetBody();
CCNode* nodeA = (CCNode*)bodyA->GetUserData();
CCNode* nodeB = (CCNode*)bodyB->GetUserData();
if( nodeA != NULL && nodeB != NULL ){
//
if( nodeA->getTag() == NODE_TAG_BALL ){
Ball* pBall = (Ball*)nodeA;
pBall->contactWith(nodeB);
}
else if( nodeB->getTag() == NODE_TAG_BALL ){
Ball* pBall = (Ball*)nodeB;
pBall->contactWith(nodeA);
}
}
#if 0
// 物体にひもづくSpriteを取得
PhysicsSprite* spriteA = (PhysicsSprite*)bodyA->GetUserData();
PhysicsSprite* spriteB = (PhysicsSprite*)bodyB->GetUserData();
// 地面との衝突は無視する
if (spriteA->getTag() == Config::kTag_Ground ||
spriteB->getTag() == Config::kTag_Ground)
{
return;
}
// 衝突時の加速度を取得
b2Vec2 velocityA = bodyA->GetLinearVelocity();
b2Vec2 velocityB = bodyB->GetLinearVelocity();
CCLOG("[BeginContact] A(%f, %f) B(%f, %f)", velocityA.x, velocityA.y, velocityB.x, velocityB.y);
// 加速度が一定上の大きさだったら、ぶつかられた方を削除する
float threshold = 3;
if (pow(velocityA.x, 2) + pow(velocityA.y, 2) > pow(threshold, 2)) {
spriteB->setDeleteFlag(true);
}
if (pow(velocityB.x, 2) + pow(velocityB.y, 2) > pow(threshold, 2)) {
spriteA->setDeleteFlag(true);
}
#endif
}
示例2: testSeparator
void Prototype::testSeparator() {
b2Separator sep;
vector<b2Vec2>* vec = new vector<b2Vec2>();
vec->push_back(b2Vec2(-4, -4));
vec->push_back(b2Vec2(4, -4));
vec->push_back(b2Vec2(4, 0));
vec->push_back(b2Vec2(0, 0));
vec->push_back(b2Vec2(0, 4));
vec->push_back(b2Vec2(-4, 4));
m_bodyDef.position.Set((m_centerPoint.x-300)/PTM_RATIO, m_centerPoint.y/PTM_RATIO);
b2Body* body = getWorld()->CreateBody(&m_bodyDef);
try {
sep.Separate(body, &m_fixtureDef, vec, PTM_RATIO);
} catch(b2SeparatorException& e) {
CCLog("b2Separator Exception: %s", e.what());
}
// Only need below to attach box2d body to a cocos2d sprite...
PhysicsSprite* ps = new PhysicsSprite();
ps->setTag(2);
ps->setPosition( CCPointMake( m_centerPoint.x+300, m_centerPoint.y ) );
ps->setPhysicsBody(body);
body->SetUserData(ps);
m_sprites[ps->getTag()] = ps;
}
示例3: testSimple
void Prototype::testSimple() {
b2PolygonShape shape;
m_bodyDef.position.Set(m_centerPoint.x/PTM_RATIO, m_centerPoint.y/PTM_RATIO);
b2Body* body = getWorld()->CreateBody(&m_bodyDef);
shape.SetAsBox(4, 4);
m_fixtureDef.shape = &shape;
body->CreateFixture(&m_fixtureDef);
// Only need below to attach box2d body to a cocos2d sprite...
PhysicsSprite* ps = new PhysicsSprite();
ps->setTag(1);
ps->setPosition( CCPointMake( m_centerPoint.x+300, m_centerPoint.y ) );
ps->setPhysicsBody(body);
body->SetUserData(ps);
m_sprites[ps->getTag()] = ps;
}