Hello everyone. I'm attempting to load a spritefont using the content pipeline in a WinForm project, but I've hit some snags.
My first attempt seemed to be the most logical. I would simply build the spritefont at runtime using the content pipeline as I am doing with some other assets.
string buildError; |
| spriteFont = LoadContent<SpriteFont>(currentDirectory + "/font.spritefont", null, null, out buildError); |
I'm using the methods from the WinForms examples, and my LoadContent method works fine, from basic Texture2D files to my own custom content using custom reader/writers. However, this spritefont will not build.
buildError contains the following:
"Unsupported type. Cannot find a ContentTypeWriter implementation for Microsoft.Xna.Framework.Content.Pipeline.Graphics.FontDescription"
I would have preferred this implementation, but I tried for a work around.
My second attempt was basically a way to try and work around the first problem. Instead of building the spritefont from my winform project, I would just build it from another project an load it using the content manager directly using the following code:
| contentManager.Unload(); |
| object content; |
| content = contentManager.Load<SpriteFont>(currentDirectory + "/font"); |
| spriteFont = (SpriteFont)content; |
| |
| |
currentDirectory is simply the path to the executable.
When I call spriteBatch.DrawString with this font loaded, I get the following exception thrown:
"Cannot access a disposed object. Object name: 'Texture2D' "
I'm not really sure where the object is being disposed, if anywhere, as it is simply being stored in a member field in the Form.
I've also tried this without using a base object and simply doing:
spriteFont = contentManager.Load<SpriteFont>(currentDirectory + "/font");
No change.
Anyone know how to preferably get the first version working? The second would be fine also.