• Editor
  • Changing images on-the-fly with runtimes

Related Discussions
...

Hi,

If I load a skeleton into my runtime (say, libgdx), how do I assign the image to each single slot / bone?

For example, my character can change parts of clothing, or swap weapon / armor. He might put on a different boot or glove. From what I've read in the guide, I can use code to create a skin and attach it to the bone.

But if I have a scene with many character (like a MMORPG). All the characters have the same skeleton but with different hairstyles, hat, clothing, shoe, weapon etc... Do I have another way other than create skin for each of them? Would that be memory-efficient?

P/S: I searched for a similar question but cannot find one so I guess I'll make a post.

From what I've seen is you need to make each variation an attachment to the skeleton but not part of the default skin. Then, in the runtime, you assign the specific attachments to the specific bones (as defined in the exported JSON), and that will give you the variation you're looking for.

For instance, my animator designed a skeleton with a fist, a knife, and a gun. The default skin has the fist being used but, programmatically, I can assign the knife or the gun. You can do the same thing with all the body parts or define skins that use different variations by default.

I can't give you specific Java code but in C++, it looks like:

this->setAttachment("FistLeft", "knife");

Where "FistLeft" is the bone and "knife" is the attachment. (I don't want to go crazy, but I assume the API is pretty much the same but with dot notation.)

So long as all the images are part of the same sprite sheet, it should work without any problems and without any increase in memory usage. Again, my knowledge of Java in this instance is limited but in C++ it would be rendered as a batch node and, thus, a single draw command.

There's not really any penalty for defining a hundred skins that use a hundred variations of the same attachments because it's really only a JSON file being loaded. So, you can either define them as skins or just a bunch of attachments available to the skins (that you assign in your code) and it would all be pretty much the same.

I'd be curious in performance tests between assigning attachments via code versus skins but I'm willing to bet it would pretty much be a wash unless the JSON parser was really slow on your platform.

Thanks for the detailed reply.

In the most common case we will have around 30 player sitting around. Their avatars are each composed of around 12-15 image parts.

I will try and maybe get some benchmark.

19 dias depois

Thanks spudworks, spot on. Once the JSON is loaded there is no difference between setting an attachment programmatically or via a skin.