当前位置: 首页>>代码示例>>C++>>正文


C++ Map::GetObjectGroup方法代码示例

本文整理汇总了C++中tmx::Map::GetObjectGroup方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetObjectGroup方法的具体用法?C++ Map::GetObjectGroup怎么用?C++ Map::GetObjectGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tmx::Map的用法示例。


在下文中一共展示了Map::GetObjectGroup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: load

const bool MapLoader::load( const std::string filename, MapLoader::callback tile_callback, MapLoader::callback object_callback ){
	auto app = Application::getInstance();
	Tmx::Map map;

	map.ParseFile(filename);

	if( map.HasError() ){
		app->getRenderSystem().getDebugConsole()<<"\n"<<"Error Loading "<<filename<<": "<<map.GetErrorText();
		return false;
	}

	// Load all of the tilesets
	boost::unordered_map< std::string, phoenix::TexturePtr > tileset_textures;
	for (int i = 0; i < map.GetNumTilesets(); ++i) {
		const Tmx::Tileset *tileset = map.GetTileset(i);

		auto t = app->getRenderSystem().loadTexture( tileset->GetImage()->GetSource() );

		tileset_textures.insert( std::pair<std::string, phoenix::TexturePtr>( tileset->GetName(), t) );

		app->getRenderSystem().getDebugConsole()<<"\n"<<"Loaded tileset texture "<<tileset->GetImage()->GetSource()<<" for "<<tileset->GetName();
	}

	// Go through each layer
	for (int i = 0; i < map.GetNumLayers(); ++i) {
		const Tmx::Layer *layer = map.GetLayer(i);
		bea::TilemapPtr tiles = 0;

		for (int x = 0; x < layer->GetWidth(); ++x) {
			for (int y = 0; y < layer->GetHeight(); ++y) {
				auto tile_id = layer->GetTileId(x, y);
				if( tile_id == 0 ) continue;

				const Tmx::Tileset *tileset = map.FindTileset(tile_id);
				if( tileset == 0 ) continue;

				// Create the tileset when we get to the first tile in the map 
				if( !tiles ){
					tiles = new bea::Tilemap( 
						app->getObjectManager() , 
						app->getRenderSystem().getBatchRenderer(), 
						layer->GetWidth(), layer->GetHeight(),
						tileset->GetTileWidth(), tileset->GetTileHeight(),
						tileset_textures[tileset->GetName()]
					);
					app->getRenderSystem().getDebugConsole()<<"\n"<<"Added tilemap layer "<<layer->GetName()<<" with tileset "<<tileset->GetName()<<" W:"<<tiles->getMapWidth()<<" H:"<<tiles->getMapHeight();
				}

				// finally, set the tile
				tile_id -= tileset->GetFirstGid();
				if(tiles) tiles->setTile( x, y, tile_id );

				// callback
				if( tile_callback ){
					bea::PropertyContainer props;
					props["id"] = tile_id;
					props["tilemap"] = tiles;
					props["x"] = x;
					props["y"] = y;
					props["layer"] = layer->GetName();
					props["tile_width"] = tileset->GetTileWidth();
					props["tile_height"] = tileset->GetTileHeight();

					auto tile = tileset->GetTile(tile_id);
					if( tile != 0 ){
						auto tile_props = tile->GetProperties();
						if( !tile_props.Empty() ){
							auto list = tile_props.GetList();
							for( auto pit = list.begin(); pit != list.end(); ++pit ){
								props[ pit->first ] = pit->second;
							}
						}
					}

					tile_callback(props);
				}
			}
		}
		
		if( tiles ) {
			tiles->setDepth( tiles->getDepth() + (float(i)/10.0f) );
			tiles->update();
		}
	}

	// Go through the object groups
	if( object_callback ){

		for (int i = 0; i < map.GetNumObjectGroups(); ++i) {
			const Tmx::ObjectGroup *objectGroup = map.GetObjectGroup(i);
			for (int j = 0; j < objectGroup->GetNumObjects(); ++j) {

				const Tmx::Object *object = objectGroup->GetObject(j);

				bea::PropertyContainer props;
				props["name"] = object->GetName();
				props["group"] = objectGroup->GetName();
				props["type"] = object->GetType();
				props["x"] = object->GetX();
				props["y"] = object->GetY();
//.........这里部分代码省略.........
开发者ID:jonparrott,项目名称:Bea,代码行数:101,代码来源:MapLoader.cpp

示例2: main


//.........这里部分代码省略.........
                    {
                        printf("v");
                    }
                    else
                    {
                        printf(" ");
                    }
                    if (tileLayer->IsTileFlippedDiagonally(x, y))
                    {
                        printf("d ");
                    }
                    else
                    {
                        printf("  ");
                    }
                }
            }

            printf("\n");
        }
    }

    printf("\n\n");

    // Iterate through all of the object groups.
    for (int i = 0; i < map->GetNumObjectGroups(); ++i)
    {
        printf("                                    \n");
        printf("====================================\n");
        printf("Object group : %02d\n", i);
        printf("====================================\n");

        // Get an object group.
        const Tmx::ObjectGroup *objectGroup = map->GetObjectGroup(i);

        // Iterate through all objects in the object group.
        for (int j = 0; j < objectGroup->GetNumObjects(); ++j)
        {
            // Get an object.
            const Tmx::Object *object = objectGroup->GetObject(j);

            // Print information about the object.
            printf("Object Name: %s\n", object->GetName().c_str());
            printf("Object Position: (%03d, %03d)\n", object->GetX(),
                    object->GetY());
            printf("Object Size: (%03d, %03d)\n", object->GetWidth(),
                    object->GetHeight());

            if(object->GetGid() != 0) {
              printf("Object(tile) gid: %d\n", object->GetGid());
              printf("Object(tile) type: %s\n", object->GetType().c_str());
            }

            // Print Polygon points.
            const Tmx::Polygon *polygon = object->GetPolygon();
            if (polygon != 0)
            {
                for (int i = 0; i < polygon->GetNumPoints(); i++)
                {
                    const Tmx::Point &point = polygon->GetPoint(i);
                    printf("Object Polygon: Point %d: (%f, %f)\n", i, point.x,
                            point.y);
                }
            }

            // Print Polyline points.
开发者ID:andrewrk,项目名称:tmxparser,代码行数:67,代码来源:test.cpp

示例3: if


//.........这里部分代码省略.........
					isoOffset.y -= static_cast<float>(y * (tileHeight / 2u));
					isoOffset.x -= static_cast<float>(tileWidth / 2u);
					isoOffset.y += static_cast<float>(tileHeight / 2u);

					v0.position += isoOffset;
					v1.position += isoOffset;
					v2.position += isoOffset;
					v3.position += isoOffset;

					v0.color = color;
					v1.color = color;
					v2.color = color;
					v3.color = color;

					size_t id = tileInfo.tilesetID;
					if (mapLayer.m_layerSets.find(id) == mapLayer.m_layerSets.end())
					{
						mapLayer.m_layerSets.insert(std::make_pair(id, 
							std::make_shared<LayerSet>(*resultMap->m_tilesetTextures[id], 
														sf::Vector2u(map->GetWidth(), map->GetHeight()), 
														sf::Vector2u(tileWidth, tileHeight))));
					}

					mapLayer.m_layerSets[id]->AddTile(v0, v1, v2, v3, x, y, tileInfo.animated, gid);
				}
			}
		}

		resultMap->m_layers.push_back(mapLayer);
	}

	for (int i = 0; i < map->GetNumObjectGroups(); ++i)
	{
		const Tmx::ObjectGroup* objectgroup = map->GetObjectGroup(i);

		MapLayer objectLayer;
		objectLayer.m_name = objectgroup->GetName();
		objectLayer.m_opacity = objectgroup->GetOpacity();
		objectLayer.m_visible = objectgroup->IsVisible();

		for (int j = 0; j < objectgroup->GetNumObjects(); ++j)
		{
			const Tmx::Object* object = objectgroup->GetObject(j);

			MapObject resultObject;

			sf::Vector2f offset(0.0f, tileHeight / 2.0f);

			resultObject.m_position = resultMap->IsoToOrtho(static_cast<float>(object->GetX()), static_cast<float>(object->GetY())) + offset;

			if (object->GetWidth() && object->GetHeight())
			{
				float width = static_cast<float>(object->GetWidth());
				float height = static_cast<float>(object->GetHeight());
				sf::Vector2f size = sf::Vector2f(width, height);
				resultObject.m_size = size;

				const Tmx::Ellipse* ellipse = object->GetEllipse();
				if (ellipse)
				{
					const float x = size.x / 2.0f;
					const float y = size.y / 2.0f;
					const float tau = 6.283185f;
					const float step = tau / 16.0f; //number of points to make up ellipse
					for (float angle = 0.0f; angle < tau; angle += step)
					{
开发者ID:Rexagon,项目名称:licesium,代码行数:67,代码来源:MapLoader.cpp

示例4: main


//.........这里部分代码省略.........
			for (int x = 0; x < tileLayer->GetWidth(); ++x)
			{
				if (tileLayer->GetTileTilesetIndex(x, y) == -1)
				{
					printf("........    ");
				}
				else
				{
					// Get the tile's id and gid.
					printf("%03d(%03d)", tileLayer->GetTileId(x, y), tileLayer->GetTileGid(x, y));

					// Find a tileset for that id.
					//const Tmx::Tileset *tileset = map->FindTileset(layer->GetTileId(x, y));
					if (tileLayer->IsTileFlippedHorizontally(x, y))
					{
						printf("h");
					}
					else
					{
						printf(" ");
					}
					if (tileLayer->IsTileFlippedVertically(x, y))
					{
						printf("v");
					}
					else
					{
						printf(" ");
					}
					if (tileLayer->IsTileFlippedDiagonally(x, y))
					{
						printf("d ");
					}
					else
					{
						printf("  ");
					}
				}
			}

			printf("\n");
		}
	}

	printf("\n\n");

	// Iterate through all of the object groups.
	for (int i = 0; i < map->GetNumObjectGroups(); ++i)
	{
		printf("                                    \n");
		printf("====================================\n");
		printf("Object group : %02d\n", i);
		printf("====================================\n");

		// Get an object group.
		const Tmx::ObjectGroup *objectGroup = map->GetObjectGroup(i);

		// Iterate through all objects in the object group.
		for (int j = 0; j < objectGroup->GetNumObjects(); ++j)
		{
			// Get an object.
			const Tmx::Object *object = objectGroup->GetObject(j);

			// Print information about the object.
			printf("Object Name: %s\n", object->GetName().c_str());
			printf("Object Position: (%03d, %03d)\n", object->GetX(),
				   object->GetY());
			printf("Object Size: (%03d, %03d)\n", object->GetWidth(),
				   object->GetHeight());

			// Print Polygon points.
			const Tmx::Polygon *polygon = object->GetPolygon();
			if (polygon != 0)
			{
				for (int i = 0; i < polygon->GetNumPoints(); i++)
				{
					const Tmx::Point &point = polygon->GetPoint(i);
					printf("Object Polygon: Point %d: (%f, %f)\n", i, point.x,
						   point.y);
				}
			}

			// Print Polyline points.
			const Tmx::Polyline *polyline = object->GetPolyline();
			if (polyline != 0)
			{
				for (int i = 0; i < polyline->GetNumPoints(); i++)
				{
					const Tmx::Point &point = polyline->GetPoint(i);
					printf("Object Polyline: Point %d: (%f, %f)\n", i, point.x,
						   point.y);
				}
			}
		}
	}

	delete map;

	return 0;
}
开发者ID:prekel,项目名称:2016.06.01,代码行数:101,代码来源:main1.cpp

示例5: Load

bool Level::Load(const std::string& filename) {
  Tmx::Map map;
  map.ParseFile(filename);

  if(map.HasError()) {
    Debug::logger->message("Error while loading level %s: %s\n", filename.c_str(), map.GetErrorText().c_str());
    return false;
  }

  _width = map.GetWidth();
  _height = map.GetHeight();
  _tileWidth = map.GetTileWidth();
  _tileHeight = map.GetTileHeight();

  std::map<const Tmx::Tileset*, Tileset*> tilesetMap;

  for(int i = 0; i < map.GetNumTilesets(); i++) {
    const Tmx::Tileset* tmxTileset = map.GetTileset(i);

    Tileset* tileset = new Tileset(_tileWidth, _tileHeight);
    tileset->LoadImage(map.GetFilepath() + tmxTileset->GetImage()->GetSource());

    _tilesets.push_back(tileset);

    tilesetMap.insert(std::pair<const Tmx::Tileset*, Tileset*>(tmxTileset, tileset));
  }

  _collisions = new bool[_width * _height];
  for(int i = 0; i < (_width * _height); i++) {
    _collisions[i] = false;
  }

  for(int i = 0; i < map.GetNumLayers(); i++) {
    const Tmx::Layer* tmxLayer = map.GetLayer(i);

    if(!strcasecmp(tmxLayer->GetName().c_str(), "collision")) {
      for(int x = 0; x < _width; x++) {
        for(int y = 0; y < _height; y++) {
          Tmx::MapTile tile = tmxLayer->GetTile(x, y);
          _collisions[y * _width + x] = tile.tilesetId > -1;
        }
      }
      continue;
    }
    else if(!strcasecmp(tmxLayer->GetName().c_str(), "middle")) {
      _middleLayer = i;
    }

    Layer* layer = new Layer(
      tmxLayer->GetWidth(), tmxLayer->GetHeight(),
      _tileWidth, _tileHeight);

    for(int x = 0; x < layer->GetWidth(); x++) {
      for(int y = 0; y < layer->GetHeight(); y++) {
        Tmx::MapTile tmxTile = tmxLayer->GetTile(x, y);

        MapTile tile;
        if(tmxTile.tilesetId != -1) {
          const Tmx::Tileset* tmxTileset = map.GetTileset(tmxTile.tilesetId);
          tile.id = tmxTile.id;
          tile.tileset = tilesetMap.find(tmxTileset)->second;
        } else {
          tile.id = 0;
          tile.tileset = NULL;
        }
        layer->SetTile(x, y, tile);
      }
    }

    _layers.push_back(layer);
  }

  if(_middleLayer == -1) {
    _middleLayer = int(floor(float(_layers.size()) / 2.0f)); // <-- nasty
  }

  for(int i = 0; i < map.GetNumObjectGroups(); i++) {
    const Tmx::ObjectGroup* tmxGroup = map.GetObjectGroup(i);
    for(int j = 0; j < tmxGroup->GetNumObjects(); j++) {
      const Tmx::Object* tmxObject = tmxGroup->GetObject(j);
      if(!strncasecmp(tmxObject->GetName().c_str(), "NPC", 3)) {
        NPC* npc = new NPC(this);
        npc->LoadSprites(tmxObject->GetProperties().GetLiteralProperty("image").c_str());
        npc->SetXY(tmxObject->GetX(), tmxObject->GetY());
        _npcs.push_back(npc);
      }
      else if(!strncasecmp(tmxObject->GetName().c_str(), "Warp", 4)) {
        Warp* warp = new Warp();
        warp->SetXY(tmxObject->GetX(), tmxObject->GetY());
        warp->SetWidthHeight(tmxObject->GetWidth(), tmxObject->GetHeight());
        warp->SetTargetMap(tmxObject->GetProperties().GetLiteralProperty("map").c_str());
        warp->SetTargetX(tmxObject->GetProperties().GetNumericProperty("x") * 32);
        warp->SetTargetY(tmxObject->GetProperties().GetNumericProperty("y") * 32);
        _warps.push_back(warp);
      }
    }
  }

  std::map<std::string, std::string> mapProps = map.GetProperties().GetList();
  for(std::map<std::string, std::string>::iterator i = mapProps.begin(); i != mapProps.end(); ++i) {
//.........这里部分代码省略.........
开发者ID:Allanis,项目名称:LibD,代码行数:101,代码来源:Level.cpp


注:本文中的tmx::Map::GetObjectGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。