spine官方提供了换装(皮肤)的方法,但是皮肤需要提前由美术做到 spine项目上,这样的话想实现未知图片就没法使用了。然而要求是不能修改库,于是只能剑走偏锋了。
思路:
1、美术把需要换图的骨骼做成空的(没有图片的)。
2、自己创建一个图片(node),并添加到spine对象上(spine对象添加到对应的 ui上)。
3、使用 findBone 方法获取对应的骨骼对象。
4、在ui的 update 方法中设置图片的位置为骨骼的位置。
以下为示例代码:
var spine = sp.SkeletonAnimation.createWithJsonFile(res.VSbipai_json, res.VSbipai_atlas);
spine.setAnimation(0, "animation", true);
this.addChild(spine);
this._sp = spine;
spine.setPosition(ccvr.width / 2, ccvr.height / 2);
this._img = new ccui.ImageView(g_res.img_hall_head_1_png);
spine.addChild(this._img); // 将图片添加到 spine 上(不添加到对应的 spine 在接下来获取骨骼的位置后需要转换)
update: function (time)
{
var ss = this._sp.findBone("you");// 需要使用的骨骼
this._img.setPosition(ss.x, ss.y);
}