Load Content - MrScautHD/Sparkle GitHub Wiki
The ContentManager enables you to load any content of your choice and automatically unloads it when the game is stopped.
public class MyGame : Game {
public static Texture2D PlayerTexture;
public static Model PlayerModel;
public MyGame(GameSettings settings) : base(settings) { }
protected override void Load() {
base.Load();
PlayerTexture = Content.Load<Texture2D>("texture.png");
PlayerModel = Content.Load<Model>("model.glb");
}
}For this example, I will demonstrate how to do that with fonts.
public class FontProcessor : IContentProcessor {
public object Load(string path) {
return FontHelper.Load(path);
}
public void Unload(object item) {
FontHelper.Unload((Font) item);
}
}After that, you need to add it to the processor list:
public class MyGame : Game {
public MyGame(GameSettings settings) : base(settings) {}
protected override void OnRun() {
base.OnRun();
this.Content.AddProcessors(typeof(Font), new FontProcessor());
}
}