Ah, that makes sense. This is not entirely trivial I'm afraid. I haven't created an example yet that does what you need, but I can outline the approach.
As a first step, you have to load your alternative images. This is done via AssetManager.loadTexture()
, on which you can set a callback that will be called once the texture has been loaded.
https://github.com/EsotericSoftware/spine-runtimes/blob/4.1/spine-ts/spine-core/src/AssetManagerBase.ts
player.assetManager.loadTexture("https://whatever", (path, texture) => {
...
});
Next, make a copy of the existing Attachment on your already loaded skeleton. Get the slot that holds the attachment from the skeleton, then copy the attachment in the slot:
let slot = player.skeleton.findSlot("name-of-the-slot");
let attachment = slot.getAttachment();
let attachmentCopy = attachment.copy();
Next, you have to set the attachment's region, which describes the area within the texture it maps to. Since you use same sized images, this should likely look like this:
let region = {
u: 0,
v: 0,
u2: 1,
v2: 1,
width: texture.getImage().width,
height: texture.getImage().height,
degrees: 0,
offsetX: 0,
offsetY: 0,
originalWidth: texture.getImage().width,
originalHeight: texture.getImage().height,
renderObject: {
page: {
texture: texture
}
}
};
attachmentCopy.region = region;
Finally, you have to call attachmentCopy.updateRegion()
so the attachment's texture coordinates are remapped to the region you just set.
All of this is from the top of my head, so there may be dragons. Give it a try and we can iterate it if you run into issues.