Files
MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs
T
Andreas Loew 27f7983aaf don't remove subdirectories from atlas image, this makes sprite management more flexible; (#999)
example: json data can be stored in sheetdata/player.json, texture can be stored in textures/player.png; player.json contains relative path to texture: image=../textures/player.png

don't remove subdirectories from atlas region names, to be able to load multiple animations from one texture atlas without conflicting region names;
example: walk/01.png, walk/02.png, ... turn/01.png, turn/02.png, ...
2025-07-24 15:29:04 -04:00

45 lines
1.4 KiB
C#

// Copyright (c) Craftwork Games. All rights reserved.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
using System.IO;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using MonoGame.Extended.Graphics;
namespace MonoGame.Extended.Content.Pipeline.TextureAtlases;
[ContentTypeWriter]
public class TexturePackerWriter : ContentTypeWriter<TexturePackerProcessorResult>
{
protected override void Write(ContentWriter writer, TexturePackerProcessorResult result)
{
var tpFile = result.Data;
var imageAssetName = Path.ChangeExtension(tpFile.Meta.Image, null);
writer.Write(imageAssetName);
writer.Write(tpFile.Regions.Count);
foreach (var region in tpFile.Regions)
{
var regionName = Path.ChangeExtension(region.FileName, null);
writer.Write(region.Frame.X);
writer.Write(region.Frame.Y);
writer.Write(region.Frame.Width);
writer.Write(region.Frame.Height);
writer.Write(regionName);
}
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return typeof(Texture2DAtlas).AssemblyQualifiedName;
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return typeof(ContentReaders.Texture2DAtlasReader).AssemblyQualifiedName;
}
}