/// <summary> /// Converts an array of sprite filenames into a sprite sheet object. /// </summary> public override SpriteSheetContent Process(string[] input, ContentProcessorContext context) { SpriteSheetContent spriteSheet = new SpriteSheetContent(); List <BitmapContent> sourceSprites = new List <BitmapContent>(); // Loop over each input sprite filename. foreach (string inputFilename in input) { // Store the name of this sprite. string spriteName = Path.GetFileNameWithoutExtension(inputFilename); spriteSheet.SpriteNames.Add(spriteName, sourceSprites.Count); // Load the sprite texture into memory. ExternalReference <TextureContent> textureReference = new ExternalReference <TextureContent>(inputFilename); TextureContent texture = context.BuildAndLoadAsset <TextureContent, TextureContent>(textureReference, "TextureProcessor"); sourceSprites.Add(texture.Faces[0][0]); } // Pack all the sprites into a single large texture. BitmapContent packedSprites = SpritePacker.PackSprites(sourceSprites, spriteSheet.SpriteRectangles, context); spriteSheet.Texture.Mipmaps.Add(packedSprites); return(spriteSheet); }
/// <summary> /// Converts an array of sprite filenames into a sprite sheet object. /// </summary> public override SpriteSheetContent Process(SpriteSheetXMLData aInput, ContentProcessorContext aContext) { SpriteSheetContent spriteSheet = new SpriteSheetContent(); List <BitmapContent> sourceSprites = new List <BitmapContent>(); // Loop over each input sprite filename. foreach (string inputFilename in aInput.files) { // Store the name of this sprite. string spriteName = Path.GetFileNameWithoutExtension(inputFilename); spriteSheet.SpriteNames.Add(spriteName, sourceSprites.Count); // Load the sprite texture into memory. ExternalReference <TextureContent> textureReference = new ExternalReference <TextureContent>(inputFilename); TextureContent texture = aContext.BuildAndLoadAsset <TextureContent, TextureContent>(textureReference, null); ((PixelBitmapContent <Color>)texture.Faces[0][0]).ReplaceColor(aInput.colorKey, Color.TransparentBlack); sourceSprites.Add(texture.Faces[0][0]); } spriteSheet.AnimationSpeed = aInput.animationSpeed; // Pack all the sprites into a single large texture. BitmapContent packedSprites = SpritePacker.PackSprites(sourceSprites, spriteSheet.SpriteRectangles, aContext); spriteSheet.Texture.Mipmaps.Add(packedSprites); return(spriteSheet); }