本文整理汇总了C++中TMXTiledMap::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXTiledMap::addChild方法的具体用法?C++ TMXTiledMap::addChild怎么用?C++ TMXTiledMap::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXTiledMap
的用法示例。
在下文中一共展示了TMXTiledMap::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool MapLayer::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(!Layer::init());
Size winSize = Director::getInstance()->getWinSize();
// 初始化地图
TMXTiledMap* map = TMXTiledMap::create("iso-test-zorder.tmx");
map->setPosition((winSize.width - map->getContentSize().width)/2, 0);
this->addChild(map, 0, kTagTileMap);
// 初始化任务
_tamara = Sprite::create("grossinis_sister1.png");
map->addChild(_tamara, map->getChildren().size());
_tamara->retain();
int mapWidth = map->getMapSize().width * map->getTileSize().width;
int mapHeight = map->getMapSize().height * map->getTileSize().height;
_tamara->setPosition(mapWidth/2, 112);
_tamara->setAnchorPoint(Point(0.5f, 0));
_vmove = -1;
_hmove = -1;
_stepIndex = -1;
_myAstar = new Astar();
this->scheduleUpdate();
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(MapLayer::onTouchBegan, this);
this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
bRet = true;
} while (0);
return bRet;
}
示例2: testTMX
void prep::testTMX()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
//创建游戏
TMXTiledMap* tmx = TMXTiledMap::create("map.tmx");
tmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
tmx->setAnchorPoint(Vec2(0.5, 0.5));
tmx->setName("paopaot");
this->addChild(tmx);
//获取对象层
TMXObjectGroup* objects = tmx->getObjectGroup("bubble");
//对应对象层的对象数组
ValueVector container = objects->getObjects();
//遍历
for (auto obj : container) {
ValueMap values = obj.asValueMap();
//获取坐标(cocos2dx坐标)
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto buble = Sprite::create("bubble.png");
buble->setPosition(Vec2(x, y + 64));
buble->ignoreAnchorPointForPosition(true);
tmx->addChild(buble, 2);
prep::bubbles.pushBack(buble);
}
objects = tmx->getObjectGroup("wall");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto wall = Sprite::create("wall.png");
wall->setPosition(Vec2(x, y + 64));
wall->ignoreAnchorPointForPosition(true);
tmx->addChild(wall, 1);
prep::walls.pushBack(wall);
}
objects = tmx->getObjectGroup("money");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto goal = Sprite::create("money.png");
goal->setPosition(Vec2(x, y + 64));
goal->ignoreAnchorPointForPosition(true);
tmx->addChild(goal, 1);
prep::money.pushBack(goal);
}
objects = tmx->getObjectGroup("player");
container = objects->getObjects();
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
auto player = Sprite::create("player.png");
player->setPosition(Vec2(x, y + 64));
player->ignoreAnchorPointForPosition(true);
player->setName("player");
tmx->addChild(player, 1);
}
}