• Runtimes
  • [LIBGDX] how apply color to slot in frame to frame animation

  • Bearbeitet
Related Discussions
...

Hello everyone! I have an existential doubt

It happens that until now I had been using the color slot to customize my characters, such as hair, skin, clothes, etc.
and it works perfectly with normal animations in my runtime

Now it happens that for certain parts of the body I am applying (I do not know if it is called this way) frame per frame animation

I mean, using a single slot multiple skinholders that I enable or disable in the animation according to my need.

example a mouth movement:

        slot name: mouth
                   placeholder: normal
                   placeholder: semiopen
                   placeholder: open

If I change the color of the slot in the editor and play the animation, the color remains in all the images
but in my runtime the color is lost when changing from normal to others. but when I the animation back to the normal placeholder it shows the new color well.

I don't know then if my idea of ​​using the slot color is correct for this purpose, or I am forgetting to do something.

it is the code i use for change the colors

private void changeColorBySlot(Color color, String slotName) {
     Slot slot = skeleton.findSlot(slotName);
     RegionAttachment attachment = (RegionAttachment) slot.getAttachment();
     try {
         if (color != null)
             attachment.getColor().set(color);  
attachment.updateOffset(); }catch (Exception e){ Gdx.app.error("Error changing color in slot: ",slotName); } }

The slot color will tint any region or mesh attachment visible for that slot. However, your code does not set the slot color, it sets the attachment color.

To set the slot color:

private void changeColorBySlot (Color color, String slotName) {
    skeleton.findSlot(slotName).getColor().set(color);
}

Ty very much Nate!

well i need rework the code 🙂

if anyone want know how solve the attachment issue, in the actor class inside the draw method call to the changeColor and this work.

but i see better use the slot solution XD