本文整理汇总了C++中CCNode::getTag方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::getTag方法的具体用法?C++ CCNode::getTag怎么用?C++ CCNode::getTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCNode
的用法示例。
在下文中一共展示了CCNode::getTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//////////////////////////////////////////////////////////////////////////
//get kind objects
//////////////////////////////////////////////////////////////////////////
std::vector<CCNode*> LevelLayer::getChildrenByTag(int tag)
{
std::vector<CCNode*> result;
CCArray* children = this->getChildren();
for (size_t i = 0; i < children->count(); ++i)
{
CCNode* node = (CCNode*)children->objectAtIndex(i);
if(node && node->getTag() == tag)
{
result.push_back(node);
}
}
if(m_pObjectsLayer != NULL)
{
children = m_pObjectsLayer->getChildren();
for (size_t i = 0; children && i < children->count(); ++i)
{
CCNode* node = (CCNode*)children->objectAtIndex(i);
if(node && node->getTag() == tag)
{
result.push_back(node);
}
}
}
return result;
}
示例2: BeginContact
// 物理構造を持つふたつのオブジェクトが衝突した時に呼ばれる関数
void GamePhysicsContactListener::BeginContact(b2Contact* contact) {
// 衝突した2つのオブジェクトのデータを取得
CCNode* actorA = (CCNode*)contact->GetFixtureA()->GetBody()->GetUserData();
CCNode* actorB = (CCNode*)contact->GetFixtureB()->GetBody()->GetUserData();
// 衝突した2つのオブジェクトに値するタグを取得
int tagA = actorA->getTag();
int tagB = actorB->getTag();
if (!actorA || !actorB){ // データが2つ揃っていない場合はそのまま戻る
return;
} else if ((tagA == TAG_PLAYER_UNIT && tagB == TAG_DESTROYER_UNIT) || (tagA == TAG_DESTROYER_UNIT && tagB == TAG_PLAYER_UNIT)
|| (tagB == TAG_PLAYER_UNIT && tagA == TAG_DESTROYER_UNIT) || (tagB == TAG_DESTROYER_UNIT && tagA == TAG_PLAYER_UNIT)) {
// ゲームオーバー
actorA->setTag(TAG_COLLISION);
} else if(tagA == TAG_PLAYER_UNIT && tagB == TAG_MISSILE) {
// 自機のライフが1減る
actorA->setTag(TAG_PLAYER_UNIT);
} else if ((tagA == TAG_DESTROYER_UNIT && tagB == TAG_MISSILE) || (tagA == TAG_MISSILE && tagB == TAG_DESTROYER_UNIT)) {
//
actorA->setTag(TAG_DESTROYER_UNIT);
} else if ((tagA == TAG_SUBMARINE_UNIT && tagB == TAG_MISSILE) || (tagA == TAG_MISSILE && tagB == TAG_SUBMARINE_UNIT)) {
//
actorA->setTag(TAG_SUBMARINE_UNIT);
}
}
示例3: getObjectCount
//////////////////////////////////////////////////////////////////////////
//get kind objects count
//////////////////////////////////////////////////////////////////////////
int LevelLayer::getObjectCount(int tag)
{
//std::vector<CCNode*> result;
int count = 0;
CCArray* children = this->getChildren();
for (size_t i = 0; i < children->count(); ++i)
{
CCNode* node = (CCNode*)children->objectAtIndex(i);
if(node && node->getTag() == tag)
{
//result.push_back(node);
count++;
}
}
if(m_pObjectsLayer != NULL)
{
children = m_pObjectsLayer->getChildren();
for (size_t i = 0; i < children->count(); ++i)
{
CCNode* node = (CCNode*)children->objectAtIndex(i);
if(node && node->getTag() == tag)
{
//result.push_back(node);
count++;
}
}
}
return count;
//return result.size();
}
示例4: addTableCell
void CSharpTollgate::addTableCell(unsigned int uIdx, CTableViewCell * pCell)
{
const vector<StageWidget> *data = DataCenter::sharedData()->getStageData()
->getStageWidgets(m_chapter);
CStage &stage = m_stageList.at(uIdx);
for (int i = 0; i < 2; i++)
{
CCNode * node = (CCNode*)m_cell->getChildren()->objectAtIndex(i);
if (node->getTag()==1)
{
const StageWidget *widget = nullptr;
CCString *strId = CCString::createWithFormat("hero%d",uIdx+1);
for (int j=0; j<data->size();++j)
{
widget = &data->at(j);
if (widget->widgetId!=""&&widget->widgetId.compare(strId->getCString())==0)
{
CButton *btn = CButton::create(widget->normalImage.c_str());
btn->setScaleX(widget->scaleX);
btn->setScaleY(widget->scaleY);
btn->setPosition(ccp(100, 80/*btn->boundingBox().size.height*/));
btn->setAnchorPoint(ccp(0.5, 0.0));
btn->setUserData(&m_stageList.at(uIdx));
btn->setOnClickListener(this,ccw_click_selector(CSharpTollgate::onBattle));
btn->setTag(1);
pCell->addChild(btn);
if (!stage.isOpen)
{
btn->getNormalImage()->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
// btn->getSelectedImage()->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
}
break;
}
}
}
else if (node->getTag()==2)
{
CImageView *image = UICloneMgr::cloneImageView((CImageView*)node);
if (stage.star>0)
{
image->setTexture(CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("tollgate/star_%d.png",stage.star)->getCString()));
}
else
{
image->setTexture(CCTextureCache::sharedTextureCache()->addImage("tollgate/star_3.png"));
image->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
}
image->setAnchorPoint(ccp(0.5f,0));
pCell->addChild(image);
}
}
pCell->setVisible(false);
pCell->setScale(1.15f);
pCell->runAction(CCSequence::create(CCDelayTime::create(0.1f+0.15f*uIdx),CCShow::create(),CCScaleTo::create(0.05f,1.0f),CCCallFuncN::create(this,callfuncN_selector(CSharpTollgate::heroCall)),nullptr));
}
示例5: onActiveLayer
//////////////////////////////////////////////////////////////////////////
//called when level active
//////////////////////////////////////////////////////////////////////////
void LevelLayer::onActiveLayer(sActiveLevelConfig& config)
{
//
this->setTouchEnabled(true);
//
CCDirector::sharedDirector()->setLevelRenderCameraOffset(ccp(0,0));
//send active event to children
CCArray* children = this->getChildren();
if (children)
{
int childrenCount = children->count();
for (int i = 0; i < childrenCount; ++i)
{
CCNode* child = (CCNode* )children->objectAtIndex(i);
ASSERT(child != NULL, "child is NULL");
BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
if (listener)
{
listener->HandleLayerActiveEvent(child, &config);
}
}
}
if(m_pObjectsLayer != NULL)
{
/*CCNode* pNode = getSpriteSeer();
if(pNode != NULL)
{
BaseListener* listener = LevelLayer::sGetListenerByTag(pNode->getTag());
listener->HandleLayerActiveEvent(pNode, &config);
}*/
CCArray* children = m_pObjectsLayer->getChildren();
if (children)
{
int childrenCount = children->count();
for (int i = 0; i < childrenCount; ++i)
{
CCNode* child = (CCNode* )children->objectAtIndex(i);
ASSERT(child != NULL, "child is NULL");
BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
if (listener)
{
listener->HandleLayerActiveEvent(child, &config);
}
}
}
}
//get other players
//OnlineNetworkManager::sShareInstance()->sendGetOtherPlayersMessage();
}
示例6: basicViewBtnCallback
void BasicInfoView::basicViewBtnCallback(CCObject *pSender){
CCNode *node = (CCNode*)pSender;
cout << "tag = " << node->getTag() << endl;
switch (node->getTag()) {
case 0:
//m_playerInfoView = PlayerInfoView::create(this);
((m_pMenuTarget)->*(m_MenuSelector))(this,NULL);
//m_playerInfoView->showPlayerInfo();
break;
default:
break;
}
}
示例7: 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
}
示例8: scrollTo
void GUISpinView::scrollTo(int rowIndex)
{
m_targetRow = rowIndex;
if (m_targetRow >= m_itemCount || m_targetRow < 0) {
return;
}
CCNode * node = m_mainNode->getChildByTag(m_targetRow);
float h = node->getPosition().y;
float dis = -h - (kMoveRound * m_itemCount * m_itemHeight);
int th = m_itemHeight;
float r = rand()% (th-10);
r -= (th-10) * 0.5f;
CCArray * array = m_mainNode->getChildren();
if (array) {
for (int i = 0; i < array->count(); i++) {
CCNode * node = (CCNode *)array->objectAtIndex(i);
CCMoveBy * move = CCMoveBy::create(kMoveTime, CCPoint(0, dis + r));
CCEaseSineOut * easeout = CCEaseSineOut::create(move);
CCDelayTime * delay = CCDelayTime::create(0.2f);
CCMoveBy * move2 = CCMoveBy::create(0.2f, ccp(0, -r));
CCSequence * seq = CCSequence::create(easeout,delay,move2,NULL);
if (node->getTag() == m_targetRow) {
node->runAction(CCSequence::create(seq,CCDelayTime::create(0.2f),CCCallFunc::create(this, callfunc_selector(GUISpinView::scrollFinish)), NULL));
}else{
node->runAction(seq);
}
}
}
scheduleUpdate();
}
示例9: ccTouchesEnded
//////////////////////////////////////////////////////////////////////////
//called when touch end
//////////////////////////////////////////////////////////////////////////
void LevelLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
CCTouch* touch = (CCTouch*)pTouches->anyObject();
CCPoint oldPT = touch->getLocationInView();
oldPT = CCDirector::sharedDirector()->convertToGL(oldPT);
CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(oldPT);
//send touch end event to children
CCArray* children = this->getChildren();
if (children)
{
int childrenCount = children->count();
for (int i = 0; i < childrenCount; ++i)
{
CCNode* child = (CCNode* )children->objectAtIndex(i);
ASSERT(child != NULL, "child is NULL");
BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
if (listener)
{
listener->HandleLayerTouchEndEvent(child, newPT);
}
}
}
//reset touch point
m_touchWinPoint = ccp(0, 0);
}
示例10: nodeByTag
CCNode* SceneReader::nodeByTag(CCNode *pParent, int nTag)
{
if (pParent == NULL)
{
return NULL;
}
CCNode *_retNode = NULL;
CCArray *pChildren = pParent->getChildren();
if(pChildren && pChildren->count() > 0)
{
CCObject* child;
CCARRAY_FOREACH(pChildren, child)
{
CCNode* pNode = (CCNode*)child;
if(pNode && pNode->getTag() == nTag)
{
_retNode = pNode;
break;
}
else
{
_retNode = nodeByTag(pNode, nTag);
if (_retNode != NULL)
{
break;
}
}
}
示例11: buttonCallback
void PopupLayer::buttonCallback(cocos2d::CCObject *pSender){
CCNode* node = dynamic_cast<CCNode*>(pSender);
CCLog("touch tag: %d", node->getTag());
if (m_callback && m_callbackListener){
(m_callbackListener->*m_callback)(node);
}
this->removeFromParent();
}
示例12: buttonCallback
void ModelDialog::buttonCallback(cocos2d::CCObject *pSender){
CCNode* node = dynamic_cast<CCNode*>(pSender);
CCLog("touch tag: %d", node->getTag());
if (m_callback && m_callbackListener){
(m_callbackListener->*m_callback)(node,NULL);
}
close();
}
示例13: onDeactiveLayer
//////////////////////////////////////////////////////////////////////////
//called when level de-active
//////////////////////////////////////////////////////////////////////////
void LevelLayer::onDeactiveLayer()
{
this->setTouchEnabled(false);
//send de-active event to children
CCArray* children = this->getChildren();
if (children)
{
int childrenCount = children->count();
for (int i = 0; i < childrenCount; ++i)
{
CCNode* child = (CCNode* )children->objectAtIndex(i);
ASSERT(child != NULL, "child is NULL");
BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
if (listener)
{
listener->HandleLayerDeactiveEvent(child);
}
}
}
//send de-active event to children
if(getObjectLayer())
{
CCArray* children = this->getObjectLayer()->getChildren();
if (children)
{
int childrenCount = children->count();
for (int i = 0; i < childrenCount; ++i)
{
CCNode* child = (CCNode* )children->objectAtIndex(i);
ASSERT(child != NULL, "child is NULL");
BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
if (listener)
{
listener->HandleLayerDeactiveEvent(child);
}
}
}
}
}
示例14: buttonCallback
//用于完成下层的数据通信
void PoptipLayer::buttonCallback(cocos2d::CCObject *pSender){
CCNode* node = dynamic_cast<CCNode*>(pSender);
CCLog("touch tag: %d", node->getTag());
switch(node->getTag())
{
case 1: //sure
{
this->removeFromParent();
break;
}
case 2: //cancel
{
this->removeFromParent();
break;
}
default:
break;
}
}
示例15: ccTouchesBegan
//////////////////////////////////////////////////////////////////////////
//called when touch layer
//////////////////////////////////////////////////////////////////////////
void LevelLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
CCTouch* touch = (CCTouch*)pTouches->anyObject();
CCPoint oldPT = touch->getLocationInView();
oldPT = CCDirector::sharedDirector()->convertToGL(oldPT);
m_touchWinPoint = oldPT;
float deviceScale = CCDirector::sharedDirector()->getContentScaleFactor();
oldPT = CCPoint(oldPT.x * deviceScale, oldPT.y * deviceScale);
CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(oldPT);
// Note: 打断自动寻路到副本显示感叹号
TaskManager::getInstance()->InterruptAutoGoToInstanceEvent();
//by benyang: deal with npc first
if(!NPCManager::sharedManager()->processTouch(newPT))
{
//send touch begin event to children
CCArray* children = this->getChildren();
if (children)
{
int childrenCount = children->count();
for (int i = 0; i < childrenCount; ++i)
{
CCNode* child = (CCNode* )children->objectAtIndex(i);
ASSERT(child != NULL, "child is NULL");
BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
if (listener)
{
listener->HandleLayerTouchBeginEvent(child, newPT);
}
}
}
}
//上面的listener未命中,直接调用SpriteSeerListener
SpriteSeer * seer = GameManager::Get()->getHero();
if (seer)
{
BaseListener* listener = LevelLayer::sGetListenerByTag(seer->getTag());
if (listener)
{
listener->HandleLayerTouchBeginEvent(seer, newPT);
}
}
//record touch point in map
m_touchWinPoint = oldPT;
}