本文整理汇总了C++中TMXTiledMap::getObjectGroup方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXTiledMap::getObjectGroup方法的具体用法?C++ TMXTiledMap::getObjectGroup怎么用?C++ TMXTiledMap::getObjectGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXTiledMap
的用法示例。
在下文中一共展示了TMXTiledMap::getObjectGroup方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _initTower
void BattleLayer::_initTower(){
TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
TMXObjectGroup *towerObjectData = tiledMap->getObjectGroup("tower");
auto &towersData = towerObjectData->getObjects();
for (auto &towerDataItem : towersData){
ValueMap &towerData = towerDataItem.asValueMap();
// CCLOG("%s, %s", towerData["side"].asString().c_str(), towerData["type"].asString().c_str());
if (towerData["side"].asString() == "player"){
if (towerData["type"].asString() == "king"){
// _playerKingTower = Tower::createTower(TowerType::King, Side::Player, this);
playerKingTower = createTower(TowerType::King, Side::Player, this);
playerKingTower->setPosition(_battleMapSize.width / 2, 0);
_battleMap->addChild(playerKingTower, getBattleElementZOrderOnBattleMap(playerKingTower));
playerTowers.push_back(playerKingTower);
}else {
if (towerData["road"].asString() == "left"){
// _playerDefendLeftTower = Tower::createTower(TowerType::Defend, Side::Player, this);
playerDefendLeftTower = createTower(TowerType::Defend, Side::Player, this);
playerDefendLeftTower->setPosition(_battleTileSize.width * 3.5, _battleTileSize.height * 5);
_battleMap->addChild(playerDefendLeftTower, getBattleElementZOrderOnBattleMap(playerDefendLeftTower));
playerTowers.push_back(playerDefendLeftTower);
}
if (towerData["road"].asString() == "right"){
// _playerDefendRightTower = Tower::createTower(TowerType::Defend, Side::Player, this);
playerDefendRightTower = createTower(TowerType::Defend, Side::Player, this);
playerDefendRightTower->setPosition(_battleTileSize.width * 16.5, _battleTileSize.height * 5);
_battleMap->addChild(playerDefendRightTower, getBattleElementZOrderOnBattleMap(playerDefendRightTower));
playerTowers.push_back(playerDefendRightTower);
}
}
}else {
if (towerData["type"].asString() == "king"){
// _npcKingTower = Tower::createTower(TowerType::King, Side::NPC, this);
npcKingTower = createTower(TowerType::King, Side::NPC, this);
npcKingTower->setPosition(_battleMapSize.width / 2, _battleTileSize.height * 26);
_battleMap->addChild(npcKingTower, getBattleElementZOrderOnBattleMap(npcKingTower));
npcTowers.push_back(npcKingTower);
}else {
if (towerData["road"].asString() == "left"){
// _npcDefendLeftTower = Tower::createTower(TowerType::Defend, Side::NPC, this);
npcDefendLeftTower = createTower(TowerType::Defend, Side::NPC, this);
npcDefendLeftTower->setPosition(_battleTileSize.width * 3.5, _battleTileSize.height * 23);
_battleMap->addChild(npcDefendLeftTower, getBattleElementZOrderOnBattleMap(npcDefendLeftTower));
npcTowers.push_back(npcDefendLeftTower);
}
if (towerData["road"].asString() == "right"){
// _npcDefendRightTower = Tower::createTower(TowerType::Defend, Side::NPC, this);
npcDefendRightTower = createTower(TowerType::Defend, Side::NPC, this);
npcDefendRightTower->setPosition(_battleTileSize.width * 16.5, _battleTileSize.height * 23);
_battleMap->addChild(npcDefendRightTower, getBattleElementZOrderOnBattleMap(npcDefendRightTower));
npcTowers.push_back(npcDefendRightTower);
}
}
}
}
}
示例2: addMapMenu
void AttackMapLayer::addMapMenu(){
//以下全部为设置地图的窗口
TMXTiledMap * changeMap = TMXTiledMap::create("bakground(1).tmx");
this->addChild(changeMap);
float cmX = (vSize.width - changeMap->getContentSize().width) / 2;
changeMap->setPosition(Vec2(cmX, 0));
TMXObjectGroup * objectgroup = changeMap->getObjectGroup("object");
ValueMap valuemap = objectgroup->getObject("object1");
float x = valuemap.at("x").asFloat();
float y = valuemap.at("y").asFloat();
auto menuitem = MenuItemImage::create("stage-9.png", "stage-9.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_1, this));
menuitem->setPosition(Vec2(x, y));
auto menu = Menu::create(menuitem, NULL);
menu->setPosition(Vec2(cmX, 0));
//房后闪光
auto flashBG = Sprite::create("crusade_stage_7_curren.png");
flashBG->setPosition(Vec2(x , y));
//动画渐入渐出
auto flashAnimationOut = FadeOut::create(0.5);
auto flashAnimationIn = FadeIn::create(0.5);
auto seqAction = Sequence::create(flashAnimationOut, flashAnimationIn, NULL);
flashBG->runAction(RepeatForever::create(seqAction));
addChild(flashBG);
valuemap = objectgroup->getObject("object2");
x = valuemap.at("x").asFloat();
y = valuemap.at("y").asFloat();
auto menuitem1 = MenuItemImage::create("stage-19.png", "stage-19.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_2, this));
menuitem1->setPosition(Vec2(x, y));
menu->addChild(menuitem1);
valuemap = objectgroup->getObject("object3");
x = valuemap.at("x").asFloat();
y = valuemap.at("y").asFloat();
auto menuitem2 = MenuItemImage::create("stage-23.png", "stage-23.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_3, this));
menuitem2->setPosition(Vec2(x, y));
menu->addChild(menuitem2);
valuemap = objectgroup->getObject("object4");
x = valuemap.at("x").asFloat();
y = valuemap.at("y").asFloat();
auto menuitem3 = MenuItemImage::create("stage-25.png", "stage-25.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_4, this));
menuitem3->setPosition(Vec2(x, y));
menu->addChild(menuitem3);
this->addChild(menu);
}
示例3: initAllPoints
//鍔犺浇鏁屼汉琛岃蛋璺緞鐐?
void GameScene::initAllPoints()
{
//寰楀埌tmx鍦板浘
TMXTiledMap* ourMap = (TMXTiledMap*)this->getChildByTag(0);
auto Group = ourMap->getObjectGroup("Obj1");//鑾峰彇瀵硅薄灞傛暟鎹?
auto Objs = Group->getObjects();
for (auto &eachObj : Objs)
{
ValueMap& dict = eachObj.asValueMap();
float x = dict["x"].asFloat();
float y = dict["y"].asFloat();
//灏嗗悇涓偣鏁版嵁鎻愬彇骞剁敓鎴怲DPoint
TDPoint * newPoint = TDPoint::createPoint(x, y);
//灏嗘柊鐢熸垚鐨凾DPoint鍔犲叆鏍?
allPoint.pushBack(newPoint);
}
}
示例4: initMap
void MapAnalysis::initMap(char* levelName)
{
GameManager* gameManager = GameManager::getInstance();
//¶ÁÈ¡TiledµØͼ×ÊÔ´
TMXTiledMap* tiledMap = TMXTiledMap::create(levelName);
gameManager->gameLayer->addChild(tiledMap, -1);
//todo--ÊӲ¾°£¬´Ë´¦ÐÞ¸Ä!TODO!ÔƲÊ
Sprite* could1 = Sprite::create("Items/cloud1.png");
could1->setPosition(500, 500);
gameManager->bkLayer->addChild(could1);
Sprite* could2 = Sprite::create("Items/cloud2.png");
could2->setPosition(900, 700);
gameManager->bkLayer->addChild(could2);
Sprite* could3 = Sprite::create("Items/cloud3.png");
could3->setPosition(1400, 450);
gameManager->bkLayer->addChild(could3);
Sprite* could4 = Sprite::create("Items/cloud1.png");
could4->setPosition(1400 + 500, 500);
gameManager->bkLayer->addChild(could4);
Sprite* could5 = Sprite::create("Items/cloud2.png");
could5->setPosition(1400 + 700, 700);
gameManager->bkLayer->addChild(could5);
Sprite* could6 = Sprite::create("Items/cloud3.png");
could6->setPosition(1400 + 1400, 450);
gameManager->bkLayer->addChild(could6);
//BrickLayer µØ°å Spikes ·æ´Ì
TMXObjectGroup* brickLayer = tiledMap->getObjectGroup("BrickLayer");
ValueVector bricks = brickLayer->getObjects();
for (int i = 0; i < bricks.size(); i++)
{
ValueMap brick = bricks.at(i).asValueMap();
float w = brick.at("width").asFloat();
float h = brick.at("height").asFloat();
float x = brick.at("x").asFloat() + w/2.0f;
float y = brick.at("y").asFloat() + h/2.0f;
if (brick.at("name").asString() == "Brick")//̨½×
{
Brick* b = Brick::create(x, y, w, h);
gameManager->gameLayer->addChild(b);
}
else if (brick.at("name").asString() == "Wall")//ǽ
{
Wall* wa = Wall::create(x, y, w, h);
gameManager->gameLayer->addChild(wa);
}
else if (brick.at("name").asString() == "Spikes")//·æ´Ì
{
Spikes* sk = Spikes::create(x, y, w, h);
gameManager->gameLayer->addChild(sk);
}
else if (brick.at("name").asString() == "DeadRoof")//ËÀÍǫ̈½×
{
DeadRoof* dr = DeadRoof::create(x, y, w, h);
gameManager->gameLayer->addChild(dr);
}
}
//CoinLayer ½ð±Ò
TMXObjectGroup* coinLayer = tiledMap->getObjectGroup("CoinLayer");
ValueVector coins = coinLayer->getObjects();
for (int i = 0; i < coins.size(); i++)
{
ValueMap coin = coins.at(i).asValueMap();
float w = SD_FLOAT("coin_float_width");
float h = SD_FLOAT("coin_float_height");
float x = coin.at("x").asFloat() + w / 2.0f;
float y = coin.at("y").asFloat() + h / 2.0f;
Coin* c = Coin::create(x, y, w, h);
gameManager->thingLayer->addChild(c);
}
//MonsterLayer ¹ÖÎï
TMXObjectGroup* monsterLayer = tiledMap->getObjectGroup("MonsterLayer");
ValueVector monsters = monsterLayer->getObjects();
for (int i = 0; i < monsters.size(); i++)
{
ValueMap monster = monsters.at(i).asValueMap();
//MonsterEx ÈËÐ͹ÖÎï
if (monster.at("name").asString() == "MonsterEx")
{
float w = SD_FLOAT("monster_float_width");
float h = SD_FLOAT("monster_float_height");
float x = monster.at("x").asFloat() + w / 2.0f;
float y = monster.at("y").asFloat() + h / 2.0f;
MonsterEx* m = MonsterEx::create(x, y, w, h);
gameManager->monsterLayer->addChild(m);
}
//FlyingSlime ·ÉÐÐÊ·À³Ä·
if (monster.at("name").asString() == "FlyingSlime")
{
float w = SD_FLOAT("flyingslime_float_width");
float h = SD_FLOAT("flyingslime_float_height");
float x = monster.at("x").asFloat() + w / 2.0f;
float y = monster.at("y").asFloat() + h / 2.0f;
FlyingSlime* f = FlyingSlime::create(x, y, w, h);
gameManager->monsterLayer->addChild(f);
//.........这里部分代码省略.........
示例5: init
//.........这里部分代码省略.........
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, priority++);
tiledmap = TMXTiledMap::create("stage1.tmx");
mapinfo = TMXMapInfo::create("stage1.tmx");
}else if(stage_no==2){
_slushLimit=2;
auto label = LabelTTF::create(GetUTF8FromSJIS("チャンスは2回のみだ"), "Arial", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, priority++);
tiledmap = TMXTiledMap::create("stage2.tmx");
mapinfo = TMXMapInfo::create("stage2.tmx");
}else if(stage_no==2){
_slushLimit=3;
#ifdef _WINDOWS
auto label = LabelTTF::create(GetUTF8FromSJIS("3回切ってくれたまえ"), "Arial", 24);
#else
auto label = LabelTTF::create(GetUTF8FromSJIS("3回切ってくれたまえ"),"Arial",24);
#endif
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, priority++);
tiledmap = TMXTiledMap::create("stage3.tmx");
mapinfo = TMXMapInfo::create("stage3.tmx");
}else{
_slushLimit=3;
auto data = cocos2d::FileUtils::sharedFileUtils()->getStringFromFile("String.txt");
auto label = LabelTTF::create(data.c_str()/*("3回ぶった斬れ!!")*/, "MS Pゴシック", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, priority++);
tiledmap = TMXTiledMap::create("stage4.tmx");
mapinfo = TMXMapInfo::create("stage4.tmx");
}
auto soni=Sprite::create("soniko_t.png");
soni->setScale(0.5);
soni->setPosition(250,400);
addChild(soni);
Vector<TMXTilesetInfo*>& tileset = mapinfo->getTilesets();
TMXTilesetInfo* ts= tileset.at(0);
ObjectLayerParse(tiledmap->getObjectGroup("cuttable"),priority);
ObjectLayerParse(tiledmap->getObjectGroup("scaffold"),priority);
auto director = Director::getInstance();
auto listener=EventListenerTouchOneByOne::create();
listener->onTouchBegan=CC_CALLBACK_2(GamePlaying::onTouchBegan,this);
listener->onTouchMoved=CC_CALLBACK_2(GamePlaying::onTouchMoved,this);
listener->onTouchEnded=CC_CALLBACK_2(GamePlaying::onTouchEnded,this);
getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,this);
Director::getInstance()->getTextureCache()->addImage("blade.png");
auto qp=ParticleSystemQuad::create("hellfire.plist");
qp->setPosition(300,0);
addChild(qp,10);
//auto streak = MotionStreak::create(0.3f,0.01f,30.f,Color3B::WHITE,"trail.png");
//streak->setName("streak");
//streak->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED);
//addChild(streak);
//streak->setBlendFunc(b);
//cocos2d::BlendFunc b;
//b.dst=GL_ZERO;
//b.src=GL_ONE_MINUS_DST_COLOR;
//
//auto s=Sprite::create();
//s->setTextureRect(Rect(0,0,480,800));
//s->setPosition(240,400);
//s->setColor(Color3B::WHITE);
//s->setBlendFunc(b);
//s->setName("reverse");
//s->setVisible(false);
//addChild(s,65535);
scheduleUpdate();
return true;
}
示例6: loadMap
bool GameMap::loadMap(const int& level)
{
string fileName = StringUtils::format("map/map_%03d.tmx", level);
TMXTiledMap* map = TMXTiledMap::create(fileName);
m_map = map;
float scale = 1 / Director::getInstance()->getContentScaleFactor();
//GridPos
TMXObjectGroup* group = map->getObjectGroup("TowerPos");
ValueVector vec = group->getObjects();
m_gridPos.clear();
m_gridPos.resize(vec.size());
if (!vec.empty())
{
int i = 0;
for (const auto& v : vec)
{
const ValueMap& dict = v.asValueMap();
m_gridPos[i] = new GridPos(
i,
Rect(dict.at("x").asFloat(),
dict.at("y").asFloat(),
dict.at("width").asFloat(),
dict.at("height").asFloat()));
i++;
}
}
//计算临近的塔的ID
float h = group->getProperty("TowerPosHeight").asFloat() *scale;
float w = group->getProperty("TowerPosWidth").asFloat() *scale;
float dis = (h + 2)*(h + 2) + (w + 2)*(w + 2);
vector<int> GridPosID;
for (auto t1 : m_gridPos)
{
GridPosID.clear();
Point pos = t1->getPos();
for (auto t2 : m_gridPos)
{
if (t1 != t2 && pos.distanceSquared(t2->getPos())<=dis)
{
GridPosID.push_back(t2->ID);
}
}
int around[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
for (auto tid : GridPosID)
{
Rect rect = m_gridPos[tid]->getRect();
if (rect.containsPoint( Point(pos.x , pos.y + h )))around[North] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y + h )))around[NorthWest] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y )))around[West] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y - h )))around[SouthWest] = tid;
else if (rect.containsPoint( Point(pos.x , pos.y - h )))around[South] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y - h )))around[SouthEast] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y )))around[East] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y + h )))around[NorthEast] = tid;
}
t1->setAroundGridPosID(around);
}
//MonsterPath
group = map->getObjectGroup("Path");
vec = group->getObjects();
MonsterPath.clear();
if (!vec.empty())
{
vector<Point> posvec;
for (const auto& var : vec)
{
posvec.clear();
const ValueMap& dict = var.asValueMap();
const ValueVector& vec2 = dict.at("polylinePoints").asValueVector();
Point pos = Point(dict.at("x").asFloat(), dict.at("y").asFloat());
for (const auto& v : vec2)
{
const ValueMap& dict = v.asValueMap();
posvec.push_back(Point(pos.x + dict.at("x").asFloat()*scale, pos.y - dict.at("y").asFloat()*scale));
//posvec.push_back(Point(pos.x + dict.at("x").asFloat(), pos.y - dict.at("y").asFloat()));
}
MonsterPath.push_back(MapPath(dict.at("LoopTo").asInt(), posvec));
}
}
//WaveData
int waveCount= map->getProperty("WaveCount").asInt();
std::stringstream ss;
string propertyName;
WaveList.clear();
for (int i = 1; i <= waveCount; i++)
{
propertyName = StringUtils::format("Wave%03d", i);
group = map->getObjectGroup(propertyName);
CCASSERT(group != nullptr, string("propertyName :" + propertyName +" NOT found").c_str());
Wave wave;
wave.WaveTime = group->getProperty("waveTime").asInt();
//.........这里部分代码省略.........
示例7:
PushBoxScene::PushBoxScene()
{
TMXTiledMap* mytmx = TMXTiledMap::create("Pushbox/map.tmx");
mytmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
mytmx->setAnchorPoint(Vec2(0,0));
myx = (visibleSize.width - mytmx->getContentSize().width) / 2;
myy = (visibleSize.height - mytmx->getContentSize().height) / 2;
this->addChild(mytmx, 0);
count = 0;
success = 0;
/*mon = Sprite::create("Pushbox/player.png");
mon->setAnchorPoint(Vec2(0, 0));
mon->setPosition(Vec2(SIZE_BLOCK*1+myx, SIZE_BLOCK*8+myy));
mon->setTag(TAG_PLAYER);
this->addChild(mon, 1);*/
TMXObjectGroup* objects = mytmx->getObjectGroup("wall");
//从对象层中获取对象数组
ValueVector container = objects->getObjects();
//遍历对象
for (auto obj : container) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/wall.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x,y+64));
mywall.pushBack(temp);
this->addChild(temp, 1);
}
TMXObjectGroup* objects1 = mytmx->getObjectGroup("box");
//从对象层中获取对象数组
ValueVector container1 = objects1->getObjects();
//遍历对象
for (auto obj : container1) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/box.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mybox.pushBack(temp);
this->addChild(temp, 3);
}
TMXObjectGroup* objects2 = mytmx->getObjectGroup("player");
//从对象层中获取对象数组
ValueVector container2 = objects2->getObjects();
//遍历对象
for (auto obj : container2) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/player.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mon = temp;
this->addChild(temp, 2);
}
TMXObjectGroup* objects3 = mytmx->getObjectGroup("goal");
//从对象层中获取对象数组
ValueVector container3 = objects3->getObjects();
//遍历对象
for (auto obj : container3) {
ValueMap values = obj.asValueMap();
int x = values.at("x").asInt();
int y = values.at("y").asInt();
Sprite* temp = Sprite::create("Pushbox/goal.png");
temp->setAnchorPoint(Point(0, 0));
temp->setPosition(Point(x, y+64));
mygoal.pushBack(temp);
this->addChild(temp, 1);
}
}
示例8: 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);
}
}