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