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


C++ JSONValue::arrayLength方法代码示例

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


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

示例1: load

void Map::load(JSONValue &mapObject)
{
	// Check if the map is already loaded
	
	if (loaded)
		throw bit::Exception("Map is already loaded");
	
	// The map must be orthogonal
	
	if (mapObject["orientation"].toString() != "orthogonal")
		throw bit::Exception("Map must be orthogonal");
	
	// Set the tile dimensions
	
	tileSize.x = mapObject["tilewidth"].toInteger();
	tileSize.y = mapObject["tileheight"].toInteger();
	
	mapSize.x = mapObject["width"].toInteger();
	mapSize.y = mapObject["height"].toInteger();
	
	if (tileSize.x <= 0 || tileSize.y <= 0)
		throw bit::Exception("Tile dimensions must be greater than zero");
	
	// Build tilesets
	
	JSONValue tilesetArray = mapObject["tilesets"];
	int tilesetLength = tilesetArray.arrayLength();
	
	for (int index = 0; index < tilesetLength; ++index)
	{
		// Create tileset
		
		JSONValue tilesetObject = tilesetArray[index];
		loadTileset(tilesetObject);
	}
	
	// Build layers
	
	JSONValue layerArray = mapObject["layers"];
	int layerLength = layerArray.arrayLength();
	
	for (int index = 0; index < layerLength; ++index)
	{
		// Create layer
		
		JSONValue layerObject = layerArray[index];
		
		// The index (i.e. the order which the layer appears, zero-based)
		// will be its z-order number
		
		loadLayer(layerObject, index);
	}
	
	// Clear the temporary tiles map
	
	tiles.clear();
	
	loaded = true;
}
开发者ID:bagobor,项目名称:BitRPG,代码行数:59,代码来源:Map.cpp

示例2: loadMap

void MapManager::loadMap(JSONValue &mapObject)
{
	if (mapObject["orientation"].toString() != "orthogonal")
		throw bit::Exception("Map must be orthogonal");
	
	// Set the tile dimensions
	
	tileWidth = mapObject["tilewidth"].toInteger();
	tileHeight = mapObject["tileheight"].toInteger();
	
	mapWidth = mapObject["width"].toInteger();
	mapHeight = mapObject["height"].toInteger();
	
	// Build tilesets
	
	JSONValue tilesetArray = mapObject["tilesets"];
	int tilesetLength = tilesetArray.arrayLength();
	
	for (int index = 0; index < tilesetLength; ++index)
	{
		// Create tileset
		
		JSONValue tilesetObject = tilesetArray[index];
		loadTileset(tilesetObject);
	}
	
	// Build layers
	
	JSONValue layerArray = mapObject["layers"];
	int layerLength = layerArray.arrayLength();
	
	for (int index = 0; index < layerLength; ++index)
	{
		// Create layer
		
		JSONValue layerObject = layerArray[index];
		MapLayerPtr mapLayer(new MapLayer(this, layerObject));
		
		// The index (i.e. the order which the layer appears, zero-based)
		// will be its z-order number
		
		layers.insert(std::pair<int, MapLayerPtr>(index, mapLayer));
	}
}
开发者ID:Marviel,项目名称:BitRPG,代码行数:44,代码来源:MapManager.cpp

示例3: loadLayer

void Map::loadLayer(JSONValue &layerObject, int zOrder)
{
	// Check that this is a tile layer
	
	std::string type = layerObject["type"].toString();
	
	if (type != "tilelayer")
		return;
	
	// Extract layer data
	
	std::string name = layerObject["name"].toString();
	
	int mapX = layerObject["x"].toInteger();
	int mapY = layerObject["y"].toInteger();
	int mapWidth = layerObject["width"].toInteger();
	int mapHeight = layerObject["height"].toInteger();
	int mapLength = mapWidth * mapHeight;
	
	// Extract tile data
	
	JSONValue dataArray = layerObject["data"];
	int dataLength = dataArray.arrayLength();
	
	// Check that the number of gids agrees with the map dimensions
	
	if (dataLength != mapLength)
		throw bit::Exception("Layer does not have the correct number of tiles");
	
	// Iterate through each tile
	
	for (int index = 0; index < dataLength; ++index)
	{
		int gid = dataArray[index].toInteger();
		
		// If gid is zero, don't make a Graphic
		
		if (gid == 0)
			continue;
		
		int pixelX = (mapX + index % mapWidth) * tileSize.x;
		int pixelY = (mapY + index / mapWidth) * tileSize.y;
		
		// Create the Graphic from the appropriate tile
		
		shared_ptr<SharedSprite> sprite(new SharedSprite);
		sprite->setTexture(getTile(gid));
		sprite->setPosition(pixelX, pixelY);
		
		// Insert the sprite in the graphics map
		
		std::pair<int, shared_ptr<SharedSprite> > spritePair(zOrder, sprite);
		sprites.insert(spritePair);
	}
}
开发者ID:bagobor,项目名称:BitRPG,代码行数:55,代码来源:Map.cpp


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