本文整理汇总了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;
}
示例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));
}
}
示例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);
}
}