本文整理汇总了C++中SpriteSheet::setTextureName方法的典型用法代码示例。如果您正苦于以下问题:C++ SpriteSheet::setTextureName方法的具体用法?C++ SpriteSheet::setTextureName怎么用?C++ SpriteSheet::setTextureName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpriteSheet
的用法示例。
在下文中一共展示了SpriteSheet::setTextureName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: import
void SpriteImporter::import(const ImportingAsset& asset, IAssetCollector& collector)
{
String atlasName = asset.assetId;
String spriteSheetName = Path(asset.assetId).replaceExtension("").string();
std::vector<ImageData> totalFrames;
Maybe<Metadata> startMeta;
Maybe<String> palette;
for (auto& inputFile: asset.inputFiles) {
auto fileInputId = Path(inputFile.name).dropFront(1);
const String spriteName = fileInputId.replaceExtension("").string();
// Meta
Metadata meta = inputFile.metadata;
if (!startMeta) {
startMeta = meta;
}
Vector2i pivot;
pivot.x = meta.getInt("pivotX", 0);
pivot.y = meta.getInt("pivotY", 0);
Vector4s slices;
slices.x = gsl::narrow<short, int>(meta.getInt("slice_left", 0));
slices.y = gsl::narrow<short, int>(meta.getInt("slice_top", 0));
slices.z = gsl::narrow<short, int>(meta.getInt("slice_right", 0));
slices.w = gsl::narrow<short, int>(meta.getInt("slice_bottom", 0));
bool trim = meta.getBool("trim", true);
// Palette
auto thisPalette = meta.getString("palette", "");
if (palette) {
if (thisPalette != palette.get()) {
throw Exception("Incompatible palettes in atlas \"" + atlasName + "\". Previously using \"" + palette.get() + "\", now trying to use \"" + thisPalette + "\"", HalleyExceptions::Tools);
}
} else {
palette = thisPalette;
}
// Import image data
std::vector<ImageData> frames;
if (inputFile.name.getExtension() == ".ase" || inputFile.name.getExtension() == ".aseprite") {
// Import Aseprite file
frames = AsepriteReader::importAseprite(spriteName, gsl::as_bytes(gsl::span<const Byte>(inputFile.data)), trim);
} else {
// Bitmap
auto span = gsl::as_bytes(gsl::span<const Byte>(inputFile.data));
auto image = std::make_unique<Image>(span, fromString<Image::Format>(meta.getString("format", "undefined")));
frames.emplace_back();
auto& imgData = frames.back();
imgData.clip = trim ? image->getTrimRect() : image->getRect(); // Be careful, make sure this is done before the std::move() below
imgData.img = std::move(image);
imgData.duration = 100;
imgData.filenames.emplace_back(":img:" + fileInputId.toString());
imgData.frameNumber = 0;
imgData.sequenceName = "";
}
// Update frames with pivot and slices
for (auto& f: frames) {
f.pivot = pivot;
f.slices = slices;
}
// Split into a grid
const Vector2i grid(meta.getInt("tileWidth", 0), meta.getInt("tileHeight", 0));
if (grid.x > 0 && grid.y > 0) {
frames = splitImagesInGrid(frames, grid);
}
// Write animation
Animation animation = generateAnimation(spriteName, spriteSheetName, meta.getString("material", "Halley/Sprite"), frames);
collector.output(spriteName, AssetType::Animation, Serializer::toBytes(animation));
std::move(frames.begin(), frames.end(), std::back_inserter(totalFrames));
}
// Generate atlas + spritesheet
SpriteSheet spriteSheet;
auto atlasImage = generateAtlas(atlasName, totalFrames, spriteSheet);
spriteSheet.setTextureName(atlasName);
// Image metafile
auto size = atlasImage->getSize();
Metadata meta;
if (startMeta) {
meta = startMeta.get();
}
if (palette) {
meta.set("palette", palette.get());
}
meta.set("width", size.x);
meta.set("height", size.y);
meta.set("compression", "raw_image");
// Write atlas image
ImportingAsset image;
image.assetId = atlasName;
image.assetType = ImportAssetType::Image;
//.........这里部分代码省略.........