mark~~
native的MeshAttachment无法更换有排查建议吗,RegionAttachment的可以,也没报错之类,不知道怎么看
同求,这个问题不解决,很多地方也用不成
3.x 版本的局部换装的 native上更换 MeshAttachment 方案,(目前)需要定制引擎
在 3.4.0以上版本,合并以下PR
- 修改 engine cocos/spine/skeleton.ts 文件
platforms/native/engine/jsb-spine-skeleton.js 文件 - 修改 engine-native
cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp
cocos/editor-support/spine-creator-support/SkeletonRenderer.h
cocos/editor-support/spine/Attachment.cpp
cocos/editor-support/spine/Attachment.h
cocos/editor-support/spine/MeshAttachment.cpp
cocos/editor-support/spine/RegionAttachment.cpp
tools/tojs/spine.ini
备注
- 修改engine后,记得在编辑器顶部菜单栏点击编译引擎
- 修改engine-native后,记得运行 engine-native\tools\tojs目录下的genbindings.py脚本,重新生成绑定
- 用户脚本上,直接调用 changeSlotSkin(slotName, tex2d)函数完成换肤
2赞
mark~
请问这些pr会被添加到之后的哪个新版本?
如果用了自动图集的话可以用下面的方法 v2.4.8可用
/**
* 获取spine运行时图片数据
*/
private loadRegion(frame:cc.SpriteFrame):sp.spine.TextureAtlasRegion{
let texture=frame.getTexture()
let skeletonTexture = new sp.SkeletonTexture()
skeletonTexture.setRealTexture(texture)
let page = new sp.spine.TextureAtlasPage()
page.texture = skeletonTexture
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
let size=frame.getOriginalSize()
region.width = size.width
region.height = size.height
region.originalWidth = size.width
region.originalHeight = size.height
region.u = frame["uv"][0]
region.v = frame["uv"][7]
region.u2 = frame["uv"][6]
region.v2 = frame["uv"][1]
region.texture = skeletonTexture
return region
}
原生打包这个方案直接寄了。。。
spine换装,mark一个~
原生不能这么干要另外做处理
if (JSB) {
// @ts-ignore
let skeleton = cc.internal.SpineSkeleton.prototype;
// @ts-ignore
let spineSkeletonData = cc.internal.SpineSkeletonData.prototype;
// 局部换装
skeleton.updateRegion = function (attachment: any, tex2d: any) {
// @ts-ignore
var jsbTex2d = new middleware.Texture2D();
jsbTex2d.setRealTextureIndex(spineSkeletonData.recordTexture(tex2d));
jsbTex2d.setPixelsWide(tex2d.width);
jsbTex2d.setPixelsHigh(tex2d.height);
// @ts-ignore
sp.spine.updateRegion(attachment, jsbTex2d);
}
}
十分感谢,我最后还是用了官方的方案,新建了一个全部是武器的spine文件来替换使用了。。。
赞,有用。
1赞
mark~~
请问怎么用呢