Hello, I am currently working on a project that involves changing cloths and body parts for an avatar. I am using cocos creator with javascript. I am testing with spine and I am able to change cloths if they are already included in the atlas. My problem is I am gonna have hundreds of cloths for the avatar and I can't put them all in one or more atlas. I need to load dynamic images from the server and replace the cloths with those images on spine. So my question is how can I programmatically replace images of a spine with dynamically loaded images from the server.
Change the texture of attachment at runtime
- 已编辑
We are not maintaining the Cocos Creator Spine integration. Could you point me at the source code of that integration? We may be able to help if it is based on spine-ts (our TypeScript based web runtime).
Do I understand correctly, that you want to download individual images (e.g. one for pants, one for shoes, one for eye brows, etc.), then combine them into an atlas at runtime, and use this atlas for a Spine skeleton? This will require that all the individual images for a part (e.g. eye brows) are the exact same size. You then need a runtime atlas packer (maybe Cocos Creator supports this?) that can pack the individual images into an atlas, using the proper image names so the Spine Runtime can later read the images from the atlas by name.
I'm not sure if Cocos Creator with JavaScript uses our atlas format or their own format.
Thank you for the reply. Yes, the logic should be as you mentioned above. Also we use same sized images for eyes, mouths etc. In cocos creator, we implement a component for spine and call it at runtime like this.
var spine = node.getComponent(sp.Skeleton);
// Change the attachment
spine.setAttachment("eye", "eye_surprised"); // slot, attachment
I am a beginner in spine and cocos so I need to clarify this. Do I need to combine images to produce an atlas in order to change images? Do I always need to use an atlas to change images for spine? Is there any ways, I could just change the images like its sprite at the attachment level? Even not in javascript, can it be done in C# or something? Thank you!
Given the current setup, it's probably easiest to combine individual images into an atlas and hand that to Spine when loading a skeleton. I'm afraid I'm not at all familiar with the way Cocos Creator and its Spine integration work, so I can't give a definite answer on how to achieve the atlas creation with their APIs.