How to mix spine skins?

How to mix spine skins?


I’m looking for a way to mix spine skins.

An ideal way for me is to use Skin API documented here:

a sample code is like this. (this sample code is used in a lua project)

    local skinNames = ["headA", "bodyB", "legC"]
    local mixedSkin ="mixed")
    for _, skinName in pairs(skinNames) do
        local skin =
        local attachmentsA = skin.attachments
        for slotIndex, attachments in pairs(attachmentsA) do
            for name, attachment in pairs(attachments) do
                mixedSkin:addAttachment(slotIndex, name, attachment)

but it seems that cocos creator’s API does not provides Skin class nor Skeleton.setSkin(skin) according to this page:

Is there a way to mix skins?


Maybe there’s an elegant way to import the engine module, then get the Skin prototype from spine.Skin.


However, at least here’s a hacky way to get the Skin prototype through the default skin object.

    // Get spine component.
    var skeletonComp = this.getComponent('sp.Skeleton');
    // Find default skin.
    var _skeleton = skeletonComp._skeleton;
    var defaultSkin ='default');
    // Get skin prototype (you can cache it for later use).
    let SkinProto = Object.getPrototypeOf(defaultSkin);

Then create a new skin object with prototype.

    let mixedSkin = Object.create(SkinProto); = 'mixed';
    mixedSkin.attachments = [];

For the rest follow the lua script you shared.