i want to load a scml-file created with Spriter. I use monogame 3.8 and it will be no problem to don’t use the conten-pipline for this, but i don’t know how to do it.
Has anyone done this and can trigger me to the right way to do?
I got it working. For all who maybe need this here is a quick info of what i did:
declare all things we need:
private readonly List animators = new List();
private MonoGameAnimator animator;
public static readonly Config SpriterConfig = new Config
{
MetadataEnabled = true,
EventsEnabled = true,
PoolingEnabled = true,
TagsEnabled = true,
VarsEnabled = true,
SoundsEnabled = false
};
Spriter spriter;
in LoadContent():
var sdata = File.ReadAllText(“Content/GreyGuy/player.scml”);
var rootFolder = “GreyGuy”;
spriter = SpriterReader.Default.Read(sdata);
DefaultProviderFactory<ISprite, SoundEffect> factory = new DefaultProviderFactory<ISprite, SoundEffect>(SpriterConfig, true);
if (spriter != null)
{
foreach(SpriterFolder folder in spriter.Folders)
{
if (spriter.Atlases != null && spriter.Atlases.Length > 0)
{
// AddAtlasFolder(folder, factory, spriter); // I don't use SpriteAtlas so you have to write your own function here
}
else
{
AddRegularFolder(folder, rootFolder, factory, spriter);
}
}
}
Stack<SpriteDrawInfo> drawInfoPool = new Stack<SpriteDrawInfo>();
foreach (SpriterEntity entity in spriter.Entities)
{
var animator = new MonoGameAnimator(entity, factory, drawInfoPool);
animators.Add(animator);
animator.Position = new Vector2(100, 400);
}
animator = animators.First();
animator.Play("walk");
animator.Position = new Vector2(400, 400);
The AddRegularFolder()-function:
private void AddRegularFolder(SpriterFolder folder, string rootFolder, DefaultProviderFactory<ISprite, SoundEffect> factory, Spriter spriter)
{
contentHelper = new ContentHelper(GraphicsDevice, Content);
contentHelper.OpenZipArchive();