Spriter animation, WP8 and reactivation

I am using a custom content format for my spriter animations (originally NowSayPillow’s Spriter implementation for XNA). Within this format, I have a list of Texture2DContexts that are loaded splendidly upon starting the app with Content.Load(filename). It generates a sprite sheet Texture2DContext out of all the individual textures within an SCML animation file.

However, when I resume it after deactivating it (Windows Phone 8 -> Windows Button -> Back), the normal textures, loaded with Content.Load are reloaded correctly, but the ones inside my custom type are not.

Supposedly, MonoGame’s ContentManager holds the resource names and reloads them when the app is resumed, but the Texture2DContexts created within my custom type are not being loaded anymore (even though it goes through the Importer-Processor pipeline). Instead, as far as I can tell, it tries to fetch them from cache and the result is nothing being drawn. It doesn’t crash though so there’s no stacktrace.

I know that any pragmatically loaded assets should be reloaded (such as render target content), but technically I am reloading this through the ContentManager. How can I force the reconstruction of the spritesheet. It should be noted here, that what the AnimationProcessor does is that it constructs a spritesheet from a bunch of Texture2Ds (Much like the XNA SpriteSheetSample). Calling the Content.Load<> again manually appears to do nothing and I believe this is already done by Monogame.

Here’s the BuildSpriteSheet function from NowSayPillow’s original code. The ContentProcessor’s Process method is essentially “return BuildSpriteSheet()”:

/// Convert sprites into sprite sheet object
        /// (Basically from XNA SpriteSheetSample project)
        ///
        public SpriterShadowData BuildSpriteSheet(XDocument p_input, ContentProcessorContext p_context) {
            SpriterShadowData l_return = new SpriterShadowData();
            l_return.Rectangles = new List<List>();
            l_return.Textures = new List();
            l_return.XML = p_input;

String p_fileName = (new List(l_return.XML.Root.Descendants(“File”)))[0].Attribute(“path”).Value;

List l_removedTextures = new List();

foreach (XElement l_folder in l_return.XML.Root.Descendants(“folder”)) {
                List l_sourceSprites = new List();

Texture2DContent l_outputTexture = new Texture2DContent();
                List l_outputRectangles = new List();

foreach (XElement l_file in l_folder.Descendants(“file”)) {
                    ExternalReference l_textureReference = new ExternalReference(p_fileName + @"" + l_file.Attribute(“name”).Value);

if (!File.Exists(l_textureReference.Filename))
                    {
                        int l_fileId;
                        GetAttributeInt32(l_file, “id”, out l_fileId);
                        l_removedTextures.Add(l_fileId);
                    }
                    else
                    {
                        TextureContent texture = p_context.BuildAndLoadAsset<TextureContent, TextureContent>(l_textureReference, “TextureProcessor”);
                        l_sourceSprites.Add(texture.Faces[0][0]);
                    }
                }

// Pack all the sprites onto a single texture.
                BitmapContent l_packedSprites = SpritePacker.PackSprites(l_sourceSprites, l_outputRectangles, p_context);
                l_outputTexture.Mipmaps.Add(l_packedSprites);

// Add dummy rectangles for removed textures
                foreach (var l_fileId in l_removedTextures)
                {
                    l_outputRectangles.Insert(l_fileId, new Rectangle(-1,-1,0,0));
                }

//  Add the data to the return type
                l_return.Rectangles.Add(l_outputRectangles);
                l_return.Textures.Add(l_outputTexture);
            }

return l_return;
        }

[edit] I guess I slightly brainfarted here as the importer-processor functionality is gone through when creating the SpriteSheet. Problem is with the loading and the loading alone as it doesn’t seem to reload the sheet.

1 Like