Chounard

I've written a bit of code to simplify loading Spine Atlas and SkeletonData files through the XNA Content Pipeline.

Note: This is unfortunately finicky to set up, so I only recommend it if you're already familiar with the Content Pipeline, and you prefer to use it. Also, while Atlas is perfect, using the Content Pipeline for SkeletonData will mostly just be for the convenience of having a ContentManager act as an asset cache for you. Spine's classes are not designed in a way that would allow for use of the automatic XNB serializer, and doing the work to create ContentWriter/Reader classes for each of Spine's classes isn't really worth the effort.

If you'd like to use the code, you'll need four files.

https://github.com/ThirdPartyNinjas/Nin ... ions/Spine

1) AtlasPipeline.cs
2) SkeletonDataPipeline.cs
Add these to a Content Pipeline extension project.

https://github.com/ThirdPartyNinjas/Nin ... harp/Spine

3) AtlasReader.cs
4) SkeletonDataReader.cs
Add these to a Game or Library project.

Make sure your Content Pipeline extension project is added to Content project references, then you can set the importers and processors. For atlases, choose "Atlas Importer - Spine" and "Atlas Processor - Spine." And for SkeletonData, choose "SkeletonData Importer - Spine" and "SkeletonData Processor - Spine."

Next, in the ContentProcessor parameters (expand the drop down next to the processor) you need to set the name of the atlas. This is the same asset name you would use to load in game using a ContentManager.

Finally, load the SkeletonData using a ContentManager: (No need to load the atlas yourself.)
SkeletonData skeletonData = Content.Load<SkeletonData>("MySkeletonData");
One more note, in that second folder, you might have noticed a class called SkeletonRenderer. That's what I use to render Spine skeletons using a replacement SpriteBatch class that I wrote that allows for Matrix transforms per draw. This makes it easy to apply transforms to the skeleton without a bunch of SpriteBatch.Begin/End killing your frame rate.
Avatar
Chounard

Kickstarter Backer
Postovi: 50

Nate

Good stuff, thanks! :)

Should probably mention the SpriteBatch based rendering can't render skewed images. Note the SkeletonRenderer in spine-csharp is a modified copy/paste of the MonoGame SpriteBatch without SRT per sprite and which exposes the vertices directly. It has Begin/End and can batch across Skeleton instances. If you mix using it with SpriteBatch though of course they will batch separately.
Avatar
Nate

Nate
Postovi: 7647


Natrag na Editor