本文整理汇总了C++中CCTMXTiledMap::getChildByTag方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXTiledMap::getChildByTag方法的具体用法?C++ CCTMXTiledMap::getChildByTag怎么用?C++ CCTMXTiledMap::getChildByTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTMXTiledMap
的用法示例。
在下文中一共展示了CCTMXTiledMap::getChildByTag方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccTouchEnded
void RPGMapSceneLayer::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
if(this->m_touchedDialogNPC)
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
CCPoint point = touch->getLocation();
point = bgMap->convertToNodeSpace(point);
if(this->m_touchedDialogNPC->boundingBox().containsPoint(point))
{
this->m_touchedDialogNPC->stopAutoMove(); //暂时停止自动移动
this->enabledControl(false);
string content = this->m_touchedDialogNPC->m_content->getCString();
RPGMapDialogLayer *dialogLayer = RPGMapDialogLayer::create(this->m_stringList, &this->m_db, this->m_touchedDialogNPC);
this->addChild(dialogLayer);
CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
mainMenu->setVisible(false);
//player和NPC互相对着
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
switch (this->m_dialogDirection)
{
case kRPGMapSceneLayerDialogDirectionUp:
{
player->setDirection(kRPGMapRoleSpriteDirectionDown);
this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionUp);
}
break;
case kRPGMapSceneLayerDialogDirectionDown:
{
player->setDirection(kRPGMapRoleSpriteDirectionUp);
this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionDown);
}
break;
case kRPGMapSceneLayerDialogDirectionLeft:
{
player->setDirection(kRPGMapRoleSpriteDirectionRight);
this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionLeft);
}
break;
case kRPGMapSceneLayerDialogDirectionRight:
{
player->setDirection(kRPGMapRoleSpriteDirectionLeft);
this->m_touchedDialogNPC->setDirection(kRPGMapRoleSpriteDirectionRight);
}
break;
default:
break;
}
}
}
this->m_touchedDialogNPC = NULL;
this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionNone;
}
示例2: joystickEndedFunc
void RPGMapSceneLayer::joystickEndedFunc()
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
mainMenu->setVisible(true);
player->stopMove();
}
示例3: init
bool RPGDialogLayer::init(string titleStr, string menuOKStr, int menuItemOKTag, string menuCancelStr, int menuItemCancelTag, float width, float height, CCObject* target, SEL_MenuHandler seletor)
{
if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height))
{
this->initCommons(titleStr);
CCTMXTiledMap *mainBg = (CCTMXTiledMap*)this->getChildByTag(kRPGDialogLayerBg);
CCMenu *menu = (CCMenu*)mainBg->getChildByTag(kRPGDialogLayerBgMenu);
CCLabelTTF *menuOKLab = CCLabelTTF::create(OzgCCUtility::generalString(CCString::create(menuOKStr)->getCString()).c_str(), "Arial", 20, CCSizeMake(120, 25), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
menuOKLab->setColor(ccc3(160, 160, 160));
CCMenuItemLabel *menuOK = CCMenuItemLabel::create(menuOKLab, target, seletor);
menuOK->setTag(menuItemOKTag);
menuOK->setPosition(ccp(100, 60));
menu->addChild(menuOK);
CCLabelTTF *menuCancelLab = CCLabelTTF::create(OzgCCUtility::generalString(CCString::create(menuCancelStr)->getCString()).c_str(), "Arial", 20, CCSizeMake(120, 25), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
menuCancelLab->setColor(ccc3(160, 160, 160));
CCMenuItemLabel *menuCancel = CCMenuItemLabel::create(menuCancelLab, target, seletor);
menuCancel->setTag(menuItemCancelTag);
menuCancel->setPosition(ccp(280, 60));
menu->addChild(menuCancel);
return true;
}
return false;
}
示例4: doMoving
bool RPGMapSceneLayer::doMoving(cocos2d::CCPoint targetPoint)
{
//这里的逻辑跟RPGMapNPCRoleSprite::autoMove类似
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
CCTMXObjectGroup *obstaclesObjects = bgMap->objectGroupNamed("obstacles");
targetPoint = ccpAdd(player->getPosition(), targetPoint);
//地图上的障碍物
for (int i = 0; i < obstaclesObjects->getObjects()->count(); i++)
{
CCDictionary *obstaclesObject = (CCDictionary*)obstaclesObjects->getObjects()->objectAtIndex(i);
const CCString *x = obstaclesObject->valueForKey("x");
const CCString *y = obstaclesObject->valueForKey("y");
const CCString *width = obstaclesObject->valueForKey("width");
const CCString *height = obstaclesObject->valueForKey("height");
CCRect obstaclesRect = CCRectMake(stringToNumber<float>(x->getCString()), stringToNumber<float>(y->getCString()), stringToNumber<float>(width->getCString()), stringToNumber<float>(height->getCString()));
if(obstaclesRect.containsPoint(targetPoint))
return false;
}
//NPC或Player
for (int i = 0; i < bgMap->getChildren()->count(); i++)
{
CCObject *item = bgMap->getChildren()->objectAtIndex(i);
if(dynamic_cast<RPGMapRoleSprite*>(item) != NULL)
{
//如果为非player的对象才会执行里面的判断
if(item != player)
{
if(((RPGMapRoleSprite*)item)->boundingBox().containsPoint(targetPoint))
return false;
}
}
}
return true;
}
示例5: enabledControl
void RPGMapSceneLayer::enabledControl(bool enabled)
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
OzgJoystickLayer *joystick = (OzgJoystickLayer*)this->getChildByTag(kRPGMapSceneLayerTagJoystick);
if(enabled)
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
joystick->active();
mainMenu->setVisible(true);
}
else
{
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
joystick->inactive();
mainMenu->setVisible(false);
}
}
示例6: playerMoveEnd
void RPGMapSceneLayer::playerMoveEnd()
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
player->stopMove();
player->stopActionByTag(kRPGMapSceneLayerActTagPlayerMove);
this->m_playerMoveAct = NULL;
//地图切换点的判断
CCTMXObjectGroup *transitionsObjects = bgMap->objectGroupNamed("transitions");
for (int i = 0; i < transitionsObjects->getObjects()->count(); i++)
{
CCDictionary *transitionsObject = (CCDictionary*)transitionsObjects->getObjects()->objectAtIndex(i);
const CCString *x = transitionsObject->valueForKey("x");
const CCString *y = transitionsObject->valueForKey("y");
const CCString *width = transitionsObject->valueForKey("width");
const CCString *height = transitionsObject->valueForKey("height");
const CCString *mapId = transitionsObject->valueForKey("map_id");
const CCString *playerToX = transitionsObject->valueForKey("player_to_x");
const CCString *playerToY = transitionsObject->valueForKey("player_to_y");
const CCString *playerDirection = transitionsObject->valueForKey("player_direction");
CCRect transitionsRect = CCRectMake(stringToNumber<float>(x->getCString()), stringToNumber<float>(y->getCString()), stringToNumber<float>(width->getCString()), stringToNumber<float>(height->getCString()));
if(transitionsRect.containsPoint(player->getPosition()))
{
// CCLog("切换场景%s", mapId->getCString());
//数据库部分,更新进度记录
//修正偏差位置,因为无法得知下一个地图的大小,所以目前只能在tmx上面定死
float toX = stringToNumber<float>(playerToX->getCString()) + 0.5;
float toY = stringToNumber<float>(playerToY->getCString()) + 0.5;
//保存数据
RPGSaveData *saveDataObj = RPGSaveData::create();
saveDataObj->m_mapId = stringToNumber<int>(mapId->getCString());
saveDataObj->m_playerToX = toX;
saveDataObj->m_playerToY = toY;
saveDataObj->m_playerDirection = playerDirection->getCString();
saveDataObj->m_gold = this->m_mapData.gold;
saveDataObj->m_windowStyle = CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE);
saveData(&this->m_db, saveDataObj);
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
this->unscheduleUpdate();
CCScene *s = RPGMapSceneLayer::scene(0.0);
CCTransitionFade *t = CCTransitionFade::create(GAME_SCENE, s);
CCDirector::sharedDirector()->replaceScene(t);
return;
}
}
//遇敌处理
// this->m_hasEnemy = true; //test
if(this->m_hasEnemy)
{
float val = CCRANDOM_0_1();
val = CCRANDOM_0_1();
if(val >= 0.0 && val <= GAME_MAP_ENCOUNTER)
{
// CCLog("遇敌!");
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
this->unscheduleUpdate();
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
CCArray *loadTextures = CCArray::create();
loadTextures->addObject(CCString::create("monsters.png"));
loadTextures->addObject(CCString::create("battle_bg.png"));
CCArray *releaseTextures = CCArray::create();
releaseTextures->addObject(CCString::create("map.png"));
releaseTextures->addObject(CCString::create("joystick.png"));
releaseTextures->addObject(CCString::create("actor4_0.png"));
releaseTextures->addObject(CCString::create("actor111.png"));
releaseTextures->addObject(CCString::create("actor113.png"));
releaseTextures->addObject(CCString::create("actor114.png"));
releaseTextures->addObject(CCString::create("actor115.png"));
releaseTextures->addObject(CCString::create("actor117.png"));
releaseTextures->addObject(CCString::create("actor120.png"));
CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
mainMenu->setEnabled(false);
SimpleAudioEngine::sharedEngine()->playEffect("audio_battle_start.wav");
// CCLog("%i", this->m_saveData.mapId);
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
CCUserDefault::sharedUserDefault()->setIntegerForKey("map_id", this->m_mapData.mapId);
CCUserDefault::sharedUserDefault()->setFloatForKey("player_to_x", player->getPosition().x / GAME_TMX_ROLE_WIDTH);
CCUserDefault::sharedUserDefault()->setFloatForKey("player_to_y", player->getPosition().y / GAME_TMX_ROLE_HEIGHT);
//.........这里部分代码省略.........
示例7: ccTouchBegan
bool RPGMapSceneLayer::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
//循环判断点击了哪一个NPC,如果有点中则m_isTouchedNPC为true
for (int i = 0; i < bgMap->getChildren()->count(); i++)
{
CCObject *item = bgMap->getChildren()->objectAtIndex(i);
if(dynamic_cast<RPGMapRoleSprite*>(item) != NULL)
{
RPGMapNPCRoleSprite *npc = (RPGMapNPCRoleSprite*)item;
if(npc->m_type == kRPGMapRoleSpriteTypeNPC)
{
//判断player是否存在该NPC的四个方向(距离为一格),存在则为true
bool exist = false;
if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(0, GAME_TMX_ROLE_HEIGHT))))
{
//上
exist = true;
this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionUp;
}
else if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(0, -GAME_TMX_ROLE_HEIGHT))))
{
//下
exist = true;
this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionDown;
}
else if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(-GAME_TMX_ROLE_WIDTH, 0))))
{
//左
exist = true;
this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionLeft;
}
else if(player->getPosition().equals(ccpAdd(npc->getPosition(), ccp(GAME_TMX_ROLE_WIDTH, 0))))
{
//右
exist = true;
this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionRight;
}
if(exist)
{
CCPoint point = touch->getLocation();
point = bgMap->convertToNodeSpace(point);
if(npc->boundingBox().containsPoint(point))
{
this->m_touchedDialogNPC = npc;
break;
}
}
}
}
}
//如果是点中了NPC则进入ccTouchEnded的处理
if(this->m_touchedDialogNPC)
return true;
else
{
//传入到摇杆的事件处理
CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu);
mainMenu->setVisible(false);
return false;
}
}
示例8: update
void RPGMapSceneLayer::update(float dt)
{
OzgJoystickLayer *joystick = (OzgJoystickLayer*)this->getChildByTag(kRPGMapSceneLayerTagJoystick);
if(!this->m_playerMoveAct && joystick && joystick->m_trigger)
{
CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
float dx = joystick->m_currentPoint.x - joystick->m_centerPoint.x;
float dy = joystick->m_currentPoint.y - joystick->m_centerPoint.y;
//CCLog("%f %f", dx, dy);
if(dx > 0 && dy > 0)
{
if(fabsf(dx) > fabsf(dy))
{
CCPoint targetPoint = ccp(GAME_TMX_ROLE_WIDTH, 0);
player->startMoveRight();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
else
{
CCPoint targetPoint = ccp(0, GAME_TMX_ROLE_HEIGHT);
player->startMoveUp();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
// CCLog("右上");
}
else if(dx > 0 && dy < 0)
{
if(fabsf(dx) > fabsf(dy))
{
CCPoint targetPoint = ccp(GAME_TMX_ROLE_WIDTH, 0);
player->startMoveRight();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
else
{
CCPoint targetPoint = ccp(0, -GAME_TMX_ROLE_HEIGHT);
player->startMoveDown();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
// CCLog("右下");
}
else if(dx < 0 && dy < 0)
{
if(fabsf(dx) > fabsf(dy))
{
CCPoint targetPoint = ccp(-GAME_TMX_ROLE_WIDTH, 0);
player->startMoveLeft();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
else
{
CCPoint targetPoint = ccp(0, -GAME_TMX_ROLE_HEIGHT);
player->startMoveDown();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
// CCLog("左下");
}
else if(dx < 0 && dy > 0)
{
if(fabsf(dx) > fabsf(dy))
{
CCPoint targetPoint = ccp(-GAME_TMX_ROLE_WIDTH, 0);
player->startMoveLeft();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
else
{
CCPoint targetPoint = ccp(0, GAME_TMX_ROLE_HEIGHT);
player->startMoveUp();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
}
// CCLog("左上");
}
else if(dx == 0 && dy > 0)
{
CCPoint targetPoint = ccp(0, GAME_TMX_ROLE_HEIGHT);
player->startMoveUp();
if(this->doMoving(targetPoint))
this->m_playerMoveAct = CCMoveBy::create(this->m_playerMoveSpeed, targetPoint);
// CCLog("上");
//.........这里部分代码省略.........
示例9: onMenu
void RPGBattleMenu::onMenu(cocos2d::CCObject *pObject)
{
CCMenuItem *menuItem = (CCMenuItem*)pObject;
SimpleAudioEngine::sharedEngine()->playEffect("audio_effect_btn.wav");
switch (menuItem->getTag())
{
case kRPGBattleMenuTagSkill:
{
CCLog("技能");
this->hideMenu();
this->m_selectedMenuTag = kRPGBattleMenuTagSkill;
CCMenuItemSprite *menuCancel = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGBattleMenu::onMenu));
menuCancel->setPosition(ccp(43, 596));
menuCancel->setTag(kRPGBattleMenuTagCancel);
menuCancel->setScale(0.75);
this->addChild(menuCancel);
CCTMXTiledMap *selectLayer = CCTMXTiledMap::create(CCString::createWithFormat("battle_select_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString());
selectLayer->setPosition(ccp((CCDirector::sharedDirector()->getWinSize().width - selectLayer->getContentSize().width) / 2, (CCDirector::sharedDirector()->getWinSize().height - selectLayer->getContentSize().height) / 2));
selectLayer->setTag(kRPGBattleSceneLayerTagSkillSelectDialog);
((RPGBattleSceneLayer*)this->m_parentNode)->addChild(selectLayer);
((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(true);
//显示title和分隔线
addLab(selectLayer, 199, (CCString*)this->m_stringList->objectForKey("skill_title"), 25, ccp(310, 285));
CCLabelTTF *titleLab = (CCLabelTTF*)selectLayer->getChildByTag(199);
titleLab->setFontFillColor(ccc3(144, 144, 144));
CCSprite *separate = CCSprite::createWithSpriteFrameName("separate.png");
separate->setPosition(ccp(selectLayer->getContentSize().width / 2, 260));
separate->setScaleX(0.65);
separate->setTag(198);
selectLayer->addChild(separate);
//加载技能数据
CCTableView *tableView = (CCTableView*)selectLayer->getChildByTag(197);
if(!tableView)
{
tableView = CCTableView::create(this, ccp(selectLayer->getContentSize().width, selectLayer->getContentSize().height - 80));
tableView->setDirection(kCCScrollViewDirectionVertical);
tableView->setPosition(CCSizeZero);
tableView->setDelegate(this);
tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
tableView->setTag(197);
selectLayer->addChild(tableView);
}
this->m_tableItems->removeAllObjects();
string wq = "";
JsonBox::Value json;
json.loadFromString(this->m_playerData->m_skill.c_str());
JsonBox::Array jsonArr = json.getArray();
for (int i = 0; i < jsonArr.size(); i++)
{
char* str = (char*)malloc(10 * sizeof(char));
OzgCCUtility::itoa(jsonArr[i].getInt(), str);
wq.append(str);
if(i + 1 < jsonArr.size())
wq.append(", ");
free(str);
}
if((int)wq.length() > 0)
{
CppSQLite3Query query = this->m_db->execQuery(CCString::createWithFormat(SKILL_QUERY, wq.c_str())->getCString());
while(!query.eof())
{
RPGSkillBtnData *skill = RPGSkillBtnData::create();
skill->m_dataId = query.getIntField("id");
skill->m_name = query.getStringField("name_cns");
skill->m_MP = query.getIntField("mp");
skill->m_skillAttack = query.getIntField("skill_attack");
skill->m_type = query.getIntField("type");
skill->m_attr = query.getIntField("attr");
skill->m_enabled = true;
//不能使用技能的情况
if(this->m_playerData->m_MP <= 0 || this->m_playerData->m_HP <= 0)
skill->m_enabled = false;
else if(this->m_playerData->m_MP < skill->m_MP)
skill->m_enabled = false;
this->m_tableItems->addObject(skill);
query.nextRow();
}
query.finalize();
}
tableView->reloadData();
//加载技能数据 end
//.........这里部分代码省略.........