spine 局部换装的方法

除了 setAttachment,有没有直接更换贴图的方式?

我有一个,但是替换的和被替换的图片必须一样大

可以动态加载单个部分图片替换,例如加载个帽子图片,替换spine动画里的帽子。

/**设置武器 */
setWeapon(bigindex,index){
cc.resources.load<cc.Texture2D>(“weapon/”+bigindex+"-"+index,cc.Texture2D,(Error,Image)=>{

        Image.handleLoadedTexture(true);
        
        let att = this.getAtt("weapon","1weapon");
        let region = this.CreateRegion(Image) 
        att.region = region
        att.setRegion(region)
 
        att.updateOffset()

   });

}

getAtt(slotName,targetAttaName){
    var targetSkinName = 'default';//皮肤的名字

    var slot = this.playerSpline.findSlot(slotName);//先获取插槽



    var skeletonData = this.playerSpline.skeletonData.getRuntimeData();//获取 Spine Runtime 使用的 SkeletonData
    var slotIndex = skeletonData.findSlotIndex(slotName);//获取插槽的index
    var skin = skeletonData.findSkin(targetSkinName);//找到对应的皮肤
    var atta = skin.getAttachment(slotIndex, targetAttaName);//获取挂件
    return atta;
}

CreateRegion(texture) {

    let skeletonTexture = new sp["SkeletonTexture"]()
    skeletonTexture.setRealTexture(texture)
    let page = new sp.spine.TextureAtlasPage()
    page.name = texture.name
    page.uWrap = sp.spine.TextureWrap.ClampToEdge
    page.vWrap = sp.spine.TextureWrap.ClampToEdge
    page.texture = skeletonTexture
    page.texture.setWraps(page.uWrap, page.vWrap)
    page.width = texture.width
    page.height = texture.height
    
    let region = new sp.spine.TextureAtlasRegion()
    region.page = page
    region.width = texture.width
    region.height = texture.height
    region.originalWidth = texture.width
    region.originalHeight = texture.height
    
    region.rotate = false
    region.u = 0
    region.v = 0
    region.u2 = 1
    region.v2 = 1
    region.texture = skeletonTexture
    return region
};
3赞

这个可以局部替换外部图片,要注意把图片勾选预乘

https://blog.csdn.net/xzben/article/details/51823263 几年前cocos2dx搞过。可以借鉴下原理

龙骨有局部换装方法么,外部图片

谢谢大家,论坛太好了

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。