cocoscreator实现spine用外部图片进行换皮
我希望可以做到外部图片替换spine一个部位上面的图片
网上有看到2dx的做法是新建sp.spine.RegionAttachment,这个时候问题就来了:
如何通过我们的Texture2D来设置sp.spine.TextureAtlasRegion和sp.spine.TextureAtlasPage
笔者研究一个礼拜,自己写了个实现函数,大家可以参考下
void SkeletonRenderer::createRegion(const std::string& slotName,cocos2d::middleware::Texture2D * texture){Slot *slot = _skeleton->findSlot(slotName.c_str());Texture* texture2D = texture->getNativeTexture();RegionAttachment* attachment = (RegionAttachment*)slot->getAttachment();float width = texture2D->getWidth();float height = texture2D->getHeight();float wide = texture->getPixelsWide();float high = texture->getPixelsHigh();attachment->setUVs(0, 0, 1,1, false);attachment->setWidth(wide);attachment->setHeight(high);attachment->setRegionWidth(wide);attachment->setRegionHeight(high);attachment->setRegionOriginalWidth(wide);attachment->setRegionOriginalHeight(high);attachment->setRegionOffsetX(0);attachment->setRegionOffsetY(15);texture->setPixelsWide(width);texture->setPixelsHigh(height);texture->setRealTextureIndex(1);AttachmentVertices * attachV = (AttachmentVertices *)attachment->getRendererObject();if (attachV->_texture == texture) return;CC_SAFE_RELEASE(attachV->_texture);attachV->_texture = texture;CC_SAFE_RETAIN(texture);V2F_T2F_C4B* vertices = attachV->_triangles->verts;for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {vertices[i].texCoord.u = attachment->getUVs()[ii];vertices[i].texCoord.v = attachment->getUVs()[ii+1];}attachment->updateOffset();}
public changeSpineTexture(slotname: string, texture2d: cc.Texture2D, size: cc.Size = null): void {if (this._spine == null || texture2d == null) {return;}let slot = this._spine.findSlot(slotname);if (slot) {let att = slot.getAttachment();if (cc.sys.isNative) {let jsbTexture = new middleware.Texture2D();let texture = texture2d.getImpl();if (size == null) {jsbTexture.setPixelsWide(texture2d.width);jsbTexture.setPixelsHigh(texture2d.height);} else {jsbTexture.setPixelsWide(size.width);jsbTexture.setPixelsHigh(size.height);}jsbTexture.setNativeTexture(texture);this._spine._nativeSkeleton.createRegion(slotname, jsbTexture);} else {texture2d.setPremultiplyAlpha(true);let skeletonTexture = new sp.SkeletonTexture();skeletonTexture.setRealTexture(texture2d);let page = new sp.spine.TextureAtlasPage();page.name = texture2d.namepage.uWrap = sp.spine.TextureWrap.ClampToEdge;page.vWrap = sp.spine.TextureWrap.ClampToEdge;page.texture = skeletonTexture;page.texture.setWraps(page.uWrap, page.vWrap);page.width = texture2d.width;page.height = texture2d.height;let region = new sp.spine.TextureAtlasRegion();region.page = page;region.width = texture2d.width;region.height = texture2d.height;region.originalWidth = texture2d.width;region.originalHeight = texture2d.height;region.rotate = false;region.u = 0;region.v = 0;region.u2 = 1;region.v2 = 1;region.texture = skeletonTexture;att.region = region;if (size != null) {att.width = size.width;att.height = size.height;}att.setRegion(region);att.updateOffset();}} else {cc.error('!!!no slot name!!=', slotname);}}
cocoscreator实现spine用外部图片进行换皮相关推荐
- Spine使用外部图片动画换肤
两种方法 制作带有空插槽的spine动画文件,找到挂载空插槽的目标slotgetNodeForSlot,在其挂载node上添加想要的元素addChild 直接使用外部texture替换相应挂载text ...
- spine 使用外部图片换装
/** * @method 更换皮肤 用外部图片 * @param sk * @param slotName * @param texture */ ChangeCloth(sk: sp.Skelet ...
- cocoscreator中spine局部换皮的探索
1.需求情况 书之国中需要一个人物捏脸系统,要求可以让用户自由选择身体不同部位的形象,比如头发.眼睛.眉毛.上衣.裤子等.已经支持RegionAttacment和MeshAttachment,而且在r ...
- cocoscreator 中 spine局部换皮
1 多attachment切换 let goblingirl = this.spine2.findSlot("left-arm");let attachment = gobling ...
- Unity Spine 局部换皮
1.Spine元素主要包含皮肤(Skin).骨骼(Bone).插槽(Slot).附件(Attachment).及附件下的图片. 2.而皮肤(Skin)包含了插槽信息.附件信息,如果我们有两套相同构成的 ...
- spine 动态换皮功能
前言: cocos2dx 中spine 的换皮功能是一种静态的方法,也就是在创建 spine 动画的时候就必须将所有的皮肤全部加载,然后在代码中直接换皮,并且这种换皮是整体的切换,对于我们实际开发中这 ...
- Unity3d载入外部图片文件
unity里的图片在生成时会压缩成资源文件,有时客户想自己放一些图片用unity显示,就必须载入外部图片. 大体思路:用Application.streamingAssetsPath或Applicat ...
- 请求外部图片的时候,遇到403的错误的解决方案
在使用angular请求外部图片时候.出现一个意外的错误. 某些图片正常显示,但是某几张却不显示, 出现如下错误, 解释为:请求被关闭,不能读取资源. 百度了很久,网上大部分观点是缓存问题,一般解决方 ...
- 淘晶驰串口屏入门(五)下拉框 选择文本 动画 视频 外部图片
一.下拉框控件 1.注意cb+数字开头的为下拉框控件 2.只有x3和x5系列的串口屏支持下拉框控件,k0,t0和t1系列不支持 3.设置path属性来给下拉框赋值,每个值之间用换行隔开 4.val属性 ...
最新文章
- 39个超实用jQuery实例应用特效
- 程序员整理的各种不错的工具
- .NET Framework终于开源了!
- 净利润跌幅超六成,坚持要做“鸭中星巴克”的周黑鸭怎么了?
- mac+修改+ssh文件夹权限_用SSH指令批量修改文件夹 文件权限和拥有者
- [机器学习] LR与SVM的异同
- Ubuntu服务器安装snmpd(用于监控宝)
- [转]JS Cookie 中文乱码
- linux kong_当Linux是善良的面Kong
- 【2019.09.07】2019徐州网络赛
- 012、JVM实战总结:案例实战:每日百万交易的支付系统,JVM栈内存与永久代大小又该如何设置?
- WEB前端超多知识总结
- JS API Sample_Query Attachments 查询附件
- 编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
- 最新大数据案例分享:2019微信数据报告(图集)
- php安装Laravel框架 全过程 傻瓜式教学
- 质心公式_No.217 质心位置的求法(基础篇)
- 大学四年对比度:看的见的青春渐变
- android刷新时的圆形动画_Android 实现倒计时动画效果
- 利器推荐:搜刮一批办公常用软件,你用过哪一款?