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


C++ SpriteSheet::addSprite方法代码示例

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


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

示例1: shrinkAtlas

std::unique_ptr<Image> SpriteImporter::makeAtlas(const std::vector<BinPackResult>& result, Vector2i origSize, SpriteSheet& spriteSheet)
{
	Vector2i size = shrinkAtlas(result);

	auto image = std::make_unique<Image>(Image::Format::RGBA, size);
	image->clear(0);

	for (auto& packedImg: result) {
		ImageData* img = reinterpret_cast<ImageData*>(packedImg.data);
		image->blitFrom(packedImg.rect.getTopLeft(), *img->img, img->clip, packedImg.rotated);

		const auto borderTL = img->clip.getTopLeft();
		const auto borderBR = img->img->getSize() - img->clip.getSize() - borderTL;

		const auto offset = Vector2f(0.0001f, 0.0001f);

		SpriteSheetEntry entry;
		entry.size = Vector2f(img->clip.getSize());
		entry.rotated = packedImg.rotated;
		entry.pivot = Vector2f(img->pivot - img->clip.getTopLeft()) / entry.size;
		entry.origPivot = img->pivot;
		entry.coords = (Rect4f(Vector2f(packedImg.rect.getTopLeft()) + offset, Vector2f(packedImg.rect.getBottomRight()) + offset)) / Vector2f(size);
		entry.trimBorder = Vector4s(short(borderTL.x), short(borderTL.y), short(borderBR.x), short(borderBR.y));
		entry.slices = img->slices;

		for (auto& filename: img->filenames) {
			spriteSheet.addSprite(filename, entry);
		}
	}

	return image;
}
开发者ID:DanMillward,项目名称:halley,代码行数:32,代码来源:sprite_importer.cpp

示例2: createSpriteSheet

SpriteSheet TexturePacker::createSpriteSheet(SpriteArray& sprites)
{
    SpriteSheet sheet;

    QImage& image = sheet.newImage(2048, 2048);
    QPainter painter(&image);
    QPoint border(1, 1);

    const int baselength = Project::getActiveProject().getImagePath().length() + 1;

    for ( const Sprite& sprite : sprites )
    {
        QImage image(sprite.mName);
        assert(!image.isNull());

        Sprite newSprite;
        newSprite.mName = sprite.mName.right(sprite.mName.length() - baselength);
        newSprite.mCoordinates = sprite.mCoordinates;
        newSprite.mOriginalSize = sprite.mOriginalSize;
        newSprite.mRotated = sprite.mRotated;
        newSprite.translate(border);
        sheet.addSprite(newSprite);

        if ( newSprite.mRotated )
        {
            RotateImagePainter rpainter(painter);
            rpainter.drawImage(newSprite.mCoordinates.topLeft(),
                               90,
                               image.width(),
                               image.height(),
                               newSprite.mCoordinates.width(),
                               newSprite.mCoordinates.height(),
                               image);
        }
        else
        {
            painter.drawImage(newSprite.mCoordinates, image);
        }
    }

    return sheet;
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:42,代码来源:texturepacker.cpp


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