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


C++ Tileset::loadFromImage方法代码示例

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


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

示例1: tr

Tileset *VariantToMapConverter::toTileset(const QVariant &variant)
{
    const QVariantMap variantMap = variant.toMap();

    const int firstGid = variantMap["firstgid"].toInt();
    const QString name = variantMap["name"].toString();
    const int tileWidth = variantMap["tilewidth"].toInt();
    const int tileHeight = variantMap["tileheight"].toInt();
    const int spacing = variantMap["spacing"].toInt();
    const int margin = variantMap["margin"].toInt();
    const QVariantMap tileOffset = variantMap["tileoffset"].toMap();
    const int tileOffsetX = tileOffset["x"].toInt();
    const int tileOffsetY = tileOffset["y"].toInt();

    if (tileWidth <= 0 || tileHeight <= 0 || firstGid == 0) {
        mError = tr("Invalid tileset parameters for tileset '%1'").arg(name);
        return 0;
    }

    Tileset *tileset = new Tileset(name,
                                   tileWidth, tileHeight,
                                   spacing, margin);
    tileset->setTileOffset(QPoint(tileOffsetX, tileOffsetY));

    const QString trans = variantMap["transparentcolor"].toString();
    if (!trans.isEmpty())
#if QT_VERSION >= 0x040700
        if (QColor::isValidColor(trans))
#endif
            tileset->setTransparentColor(QColor(trans));

    QString imageSource = variantMap["image"].toString();

    if (QDir::isRelativePath(imageSource))
        imageSource = mMapDir.path() + QLatin1Char('/') + imageSource;

    if (!tileset->loadFromImage(QImage(imageSource), imageSource)) {
        mError = tr("Error loading tileset image:\n'%1'").arg(imageSource);
        delete tileset;
        return 0;
    }

    tileset->setProperties(toProperties(variantMap["properties"]));

    QVariantMap propertiesVariantMap = variantMap["tileproperties"].toMap();
    QVariantMap::const_iterator it = propertiesVariantMap.constBegin();
    for (; it != propertiesVariantMap.constEnd(); ++it) {
        const int tileIndex = it.key().toInt();
        const QVariant propertiesVar = it.value();
        if (tileIndex >= 0 && tileIndex < tileset->tileCount()) {
            const Properties properties = toProperties(propertiesVar);
            tileset->tileAt(tileIndex)->setProperties(properties);
        }
    }

    mGidMapper.insert(firstGid, tileset);
    return tileset;
}
开发者ID:Borluse,项目名称:tiled,代码行数:58,代码来源:varianttomapconverter.cpp

示例2: f

// Reader
Tiled::Map *DroidcraftPlugin::read(const QString &fileName)
{
    using namespace Tiled;

    QByteArray uncompressed;

    // Read data
    QFile f(fileName);
    if (f.open(QIODevice::ReadOnly)) {
        QByteArray compressed = f.readAll();
        f.close();

        uncompressed = decompress(compressed, 48 * 48);
    }

    // Check the data
    if (uncompressed.count() != 48 * 48) {
        mError = tr("This is not a valid Droidcraft map file!");
        return 0;
    }

    // Build 48 x 48 map
    // Create a Map -> Create a Tileset -> Add Tileset to map
    // -> Create a TileLayer -> Fill layer -> Add TileLayer to Map
    Map *map = new Map(Map::Orthogonal, 48, 48, 32, 32);

    Tileset *mapTileset = new Tileset("tileset", 32, 32);
    mapTileset->loadFromImage(QImage(":/tileset.png"), "tileset.png");
    map->addTileset(mapTileset);

    // Fill layer
    TileLayer *mapLayer = new TileLayer("map", 0, 0, 48, 48);

    // Load
    for (int i = 0; i < 48 * 48; i++) {
        unsigned char tileFile = uncompressed.at(i);

        int y = i / 48;
        int x = i - (48 * y);

        Tile *tile = mapTileset->tileAt(tileFile);
        mapLayer->setCell(x, y, Cell(tile));
    }

    map->addLayer(mapLayer);

    return map;
}
开发者ID:kphillisjr,项目名称:tiled,代码行数:49,代码来源:droidcraftplugin.cpp


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