本文整理汇总了C++中CCTMXTiledMap::getChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXTiledMap::getChildren方法的具体用法?C++ CCTMXTiledMap::getChildren怎么用?C++ CCTMXTiledMap::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTMXTiledMap
的用法示例。
在下文中一共展示了CCTMXTiledMap::getChildren方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addChild
//------------------------------------------------------------------
//
// TMXOrthoTest
//
//------------------------------------------------------------------
TMXOrthoTest::TMXOrthoTest()
{
//
// Test orthogonal with 3d camera and anti-alias textures
//
// it should not flicker. No artifacts should appear
//
//CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
//addChild(color, -1);
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
addChild(map, 0, kTagTileMap);
CCSize s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
CCArray * pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
child->getTexture()->setAntiAliasTexParameters();
}
示例2: init
// on "init" you need to initialize your instance
bool MapScene::init()
{
if ( !CCLayer::init() )
{
return false;
}
//初始化地图
CCTMXTiledMap *map = CCTMXTiledMap::create("iso-test-zorder.tmx");
addChild(map, 0, kTagTileMap);
CCSize s = map->getContentSize();
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
map->setPosition(ccp(-s.width/2 + winSize.width/2,0));
//初始化人物
m_tamara = CCSprite::create("grossinis_sister1.png");
map->addChild(m_tamara, map->getChildren()->count() );
m_tamara->retain();
int mapWidth = map->getMapSize().width * map->getTileSize().width;
int mapHeight = map->getMapSize().height * map->getTileSize().height;
m_tamara->setPosition(ccp( mapWidth/2,112));
m_tamara->setAnchorPoint(ccp(0.5f,0));
setTouchEnabled(true);
scheduleUpdate();
vmove = -1;
hmove = -1;
stepindex = -1;
myastar = new Astar();
return true;
}
示例3: 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;
}
示例4: init
// on "init" you need to initialize your instance
bool MapScene::init()
{
//地图背景层
CCSprite *bg = CCSprite::create("background.png");
bg->setScale(1.5f);
addChild(bg, 0);
//地图初始化
CCTMXTiledMap *map = CCTMXTiledMap::create("ortho-objects.tmx");
addChild(map, 0, kTagTileMap);
CCSize s = map->getContentSize();
int mapWidth = map->getMapSize().width * map->getTileSize().width;
int mapHeight = map->getMapSize().height * map->getTileSize().height;
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
map->setPosition(ccp(0,0));
//初始化主角
gameplayer = CCSprite::create("grossini.png");
enemy = CCSprite::create("SpinningPeas.png");
map->addChild(gameplayer, map->getChildren()->count() );
map->addChild(enemy, map->getChildren()->count() );
//初始化敌人
enemy->setPosition(ccp(winSize.width/2 + 80,32));
enemy->setAnchorPoint(ccp(0.5f,0));
gameplayer->setPosition(ccp(winSize.width/2,32));
gameplayer->setAnchorPoint(ccp(0.5f,0));
setTouchEnabled(true);
scheduleUpdate();
hmove = 0;
vmove = 0;
enemymovetick = 0;
//主角矩形区域大小
ownsize = CCSizeMake(40,100);
//敌人矩形区域大小
othersize = CCSizeMake(32,32);
//是否是受伤状态
isreduce = false;
return true;
}
示例5: 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;
}
}