基于Spine3.3的换装(纸娃娃,avatar)功能
2016-07-25 00:59
876 查看
void SkeletonAnimation::SetSlotTexture(unsigned index, const std::string& slot_name, const std::string& attach_name, const std::string& texture_path) { if (index >= _custom_pages.size()) { _custom_pages.resize(index + 1, 0); } spAtlasPage* old_page = _custom_pages[index]; if (old_page) { //just return if new page equals old page if (strcmp(old_page->name, texture_path.c_str()) == 0) { return; } //release old page else { spAtlasPage_dispose(old_page); } } spAtlasPage* new_page = spAtlasPage_create(_atlas, texture_path.c_str()); new_page->magFilter = new_page->minFilter = SP_ATLAS_LINEAR; new_page->uWrap = new_page->vWrap = SP_ATLAS_CLAMPTOEDGE; _spAtlasPage_createTexture(new_page, texture_path.c_str()); // cache new_page _custom_pages[index] = new_page; int tw = new_page->width; int th = new_page->height; /* spAtlasRegion* new_reg = spAtlasRegion_create(); new_reg->page = new_page;*/ spAttachment* attach_ment = getAttachment(slot_name, attach_name); if (attach_ment && attach_ment->type == SP_ATTACHMENT_REGION) { spRegionAttachment* sp_attach = (spRegionAttachment*)attach_ment; spRegionAttachment_setUVs(sp_attach, 0, 0, 1, 1, 0); sp_attach->regionOffsetX = 0; // zero if not doing whitespace stripping sp_attach->regionOffsetY = 0; sp_attach->regionWidth = tw; sp_attach->regionHeight = th; sp_attach->regionOriginalWidth = sp_attach->regionWidth; // same if not doing whitespace stripping sp_attach->regionOriginalHeight = sp_attach->regionHeight; sp_attach->x = 0; sp_attach->y = 0; sp_attach->scaleX = 1; sp_attach->scaleY = 1; sp_attach->rotation = 0; sp_attach->width = tw; sp_attach->height = th; spRegionAttachment_updateOffset(sp_attach); AttachmentVertices* attachmentVertices = (AttachmentVertices*)sp_attach->rendererObject; attachmentVertices->_texture = (Texture2D*)new_page->rendererObject; V3F_C4B_T2F* vertices = attachmentVertices->_triangles->verts; for (int i = 0, ii = 0; i < 4; ++i, ii += 2) { vertices[i].texCoords.u = sp_attach->uvs[ii]; vertices[i].texCoords.v = sp_attach->uvs[ii + 1]; } } }
相关文章推荐
- Cocos2d-x中背景音乐和音效使用实例
- Cocos2d-x学习笔记之CCScene、CCLayer、CCSprite的默认坐标和默认锚点实验
- Cocos2d-x UI开发之CCControlPotentiometer控件类使用实例
- Cocos2d-x UI开发之文本类使用实例
- Cocos2d-x保存用户游戏数据之XML文件是否存在问题判断方法
- Cocos2d-x UI开发之菜单类使用实例
- Cocos2d-x UI开发之CCControlButton控件类实例
- Cocos2d-x学习笔记之世界坐标系、本地坐标系、opengl坐标系、屏幕坐标系
- Cocos2d-x UI开发之CCControlColourPicker控件类使用实例
- Cocos2d-x学习笔记之CCLayerColor层的使用实例
- Cocos2d-x Schedule定时器的使用实例
- Cocos2d-x中使用CCScrollView来实现关卡选择实例
- Cocos2d-x中CCEditBox文本输入框的使用实例
- cocos2d-x学习笔记之CCLayer、CCLayerColor、CCLayerGradient、CCLayerMultiplex场景层介绍
- Cocos2d-x UI开发之CCControlSlider控件类使用实例
- Cocos2d-x学习笔记之开发环境搭建
- Cocos2d-x学习笔记之Hello World!
- 使用C++进行Cocos2d-x游戏开发入门过程中的要点解析
- Cocos2d-x的内存管理总结
- Cocos2d-x 3.0中集成社交分享ShareSDK的详细步骤和常见问题解决