• Runtimes
  • [cocos2d-x] Runtime skins

  • Изменено
Related Discussions
...

Hello there.

I need to change some parts of the skeleton at runtime. I can do this with

auto* headSlot = skeleton->findSlot("head");
auto* headAttch = static_cast<spine::RegionAttachment*>(headSlot->getAttachment());
auto* headRegion = static_cast<spine::AtlasRegion*>(headAttch->getRendererObject());
headRegion->page->setRendererObject(nullptr /*new texture */);

This makes the whole skeleton black. Instead I want to create a new spine::Skin at runtime and add attachments to it. I dove into the documentation but could not find a way to do it.
http://esotericsoftware.com/spine-runtime-skins this link says that I can do it but I couldn't manage to be successful. Is there any way that this can be achieved?

Thanks.

Great timing! I'm currently working on a new API for exactly this use case. You can follow it on the skin-bones branch on GitHub. The related issue is here:

Add API to create combined skin from multiple other skins · #841

I will need another day or two to finish this up for the spine-cpp and spine-c runtimes.

месяц спустя

That's awesome news! I guess I should've looked at GitHub issues before posting here, my bad.

Thanks, keep up the good work!


badlogic написал

Great timing! I'm currently working on a new API for exactly this use case. You can follow it on the skin-bones branch on GitHub. The related issue is here:

Add API to create combined skin from multiple other skins · #841

I will need another day or two to finish this up for the spine-cpp and spine-c runtimes.

Hi again,

I think I mistold my intention of my problem. I need to be able to load different parts of skins at runtime separately (gloves, shirts, etc..) and replace the part on the current skin. Is that achievable? Do I need to create a whole new atlas texture everytime I need to replace one of the parts?

You are in full control, eg can use whatever textures you like. It's up to your game toolkit, but typically texture switches have a cost, as they cause the graphics pipeline to be flushed. It may be worth it to decide what images you need for a screen, scene, level, or similar, then pack a texture atlas at runtime with just those images. Then again, maybe you have few enough texture switches you don't need that complexity.

As for how it works, instead of using AtlasAttachmentLoader, you can provide your own which does not load textures. Later, before you render an attachment, you'll need to give it a texture and UVs. See:
Loading Skeleton Data - Spine Runtimes Guide: AttachmentLoader