本文整理汇总了C++中TileLayer::setProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ TileLayer::setProperty方法的具体用法?C++ TileLayer::setProperty怎么用?C++ TileLayer::setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileLayer
的用法示例。
在下文中一共展示了TileLayer::setProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
Tiled::Map *ReplicaIslandPlugin::read(const QString &fileName)
{
using namespace Tiled;
// Read data.
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
mError = tr("Cannot open Replica Island map file!");
return 0;
}
QDataStream in(&file);
in.setByteOrder(QDataStream::LittleEndian);
in.setFloatingPointPrecision(QDataStream::SinglePrecision);
// Parse file header.
quint8 mapSignature, layerCount, backgroundIndex;
in >> mapSignature >> layerCount >> backgroundIndex;
if (in.status() == QDataStream::ReadPastEnd || mapSignature != 96) {
mError = tr("Can't parse file header!");
return 0;
}
// Create our map, setting width and height to 0 until we load a layer.
Map *map = new Map(Map::Orthogonal, 0, 0, 32, 32);
map->setProperty("background_index", QString::number(backgroundIndex));
// Load our Tilesets.
QVector<SharedTileset> typeTilesets, tileIndexTilesets;
loadTilesetsFromResources(map, typeTilesets, tileIndexTilesets);
// Load each of our layers.
for (quint8 i = 0; i < layerCount; i++) {
// Parse layer header.
quint8 type, tileIndex, levelSignature;
float scrollSpeed;
qint32 width, height;
in >> type >> tileIndex >> scrollSpeed
>> levelSignature >> width >> height;
if (in.status() == QDataStream::ReadPastEnd || levelSignature != 42) {
delete map;
mError = tr("Can't parse layer header!");
return 0;
}
// Make sure our width and height are consistent.
if (map->width() == 0)
map->setWidth(width);
if (map->height() == 0)
map->setHeight(height);
if (map->width() != width || map->height() != height) {
delete map;
mError = tr("Inconsistent layer sizes!");
return 0;
}
// Create a layer object.
TileLayer *layer =
new TileLayer(layerTypeToName(type), 0, 0, width, height);
layer->setProperty("type", QString::number(type));
layer->setProperty("tile_index", QString::number(tileIndex));
layer->setProperty("scroll_speed", QString::number(scrollSpeed, 'f'));
map->addLayer(layer);
// Look up the tileset for this layer.
SharedTileset tileset =
tilesetForLayer(type, tileIndex, typeTilesets, tileIndexTilesets);
// Read our tile data all at once.
QByteArray tileData(width*height, '\0');
int bytesRead = in.readRawData(tileData.data(), tileData.size());
if (bytesRead != tileData.size()) {
delete map;
mError = tr("File ended in middle of layer!");
return 0;
}
quint8 *tp = reinterpret_cast<quint8 *>(tileData.data());
// Add the tiles to our layer.
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
quint8 tile_id = *tp++;
if (tile_id != 255) {
Tile *tile = tileset->findTile(tile_id);
layer->setCell(x, y, Cell(tile));
}
}
}
}
// Make sure we read the entire *.bin file.
if (in.status() != QDataStream::Ok || !in.atEnd()) {
delete map;
mError = tr("Unexpected data at end of file!");
return 0;
}
return map;
}