I couldn’t figure out how to use any images that aren’t in the spine export png’s and atlas so I use the libgdx texture packer to replace the .atlas and .png files and then you can swap them out in code. This uses an older version of the spine libraries so I’m not sure if it still works but it should be similar.
- Make sure you have Java installed.
- Put all the raw spine images (not the spine exported images) AND the images you will swap in into a folder together.
- Download libgdx texpacker.jar and put it into the folder.
- Add a new file texpacker.bat to the folder and put:
java -jar texpacker.jar .
- Add a new file pack.json to the folder and put:
- Now that you have a folder with these three files and all the images you will want in the spine double click on texpacker.bat and wait for it to complete.
- In your game replace the spine export .atlas and .png files with the ones you generated, the game should be able to load the images and work exactly as it did before.
- Here’s the function I made for swapping out the textures
internal void SetAttachmentTexture(int slotIndex, string attachmentName, string attachmentTexture, bool mirror = false)
Spine.Atlas textureAtlas = ContentManagement.ContentLoader.GetSpine("Spine/player").Atlas;
Spine.RegionAttachment attachment = (Spine.RegionAttachment)SpineSkeleton.GetAttachment(slotIndex, attachmentName);
// Change the texture region associated to the current attachment
// Inspired from AtlasAttachmentLoader.cs:NewAttachment
Spine.AtlasRegion region = textureAtlas.FindRegion(attachmentTexture.Replace("\\", "/"));
attachment.RendererObject = region;
attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
attachment.SetUVs(region.u2, region.v, region.u, region.v2, region.rotate);
attachment.RegionOffsetX = region.offsetX;
attachment.RegionOffsetY = region.offsetY;
attachment.RegionWidth = region.width;
attachment.RegionHeight = region.height;
attachment.RegionOriginalWidth = region.originalWidth;
attachment.RegionOriginalHeight = region.originalHeight;
attachment.Height = attachment.RegionOriginalHeight;
attachment.Width = attachment.RegionOriginalWidth;
which I call like this:
SetAttachmentTexture(skeleton.FindSlotIndex("hammer"), "hammer", "hammer/" + SwungWeaponComponent.TextureName);