Okay, so i wasn't after being able to edit the text from the spine editor, just place a placeholder image and do animations with it, to then later replace it with a label that would translate the animations.
I have actually come up with a solution for this that i think is quite useful for meany other things than being able to animate and edit text.
I've created a new class called GroupAttachment, that allows me to replace a RegionAttachment with a libgdx group. Then added three lines of code to the SkeletonRenderer that renders this GroupAttachment with the rest of the spine. I then simply place my label in the group, and edit the label text and style as i please through code.
The GroupAttachment works perfect with rotation, scaling, positioning and color changing done through the spine editor, but the way i add the attachment you just have to be careful that you don't replace the attachment in your animations. If you need the group out of your animation you can just set color alpha to 0.
More work could definitely be done on this in order to better integrate it into the spine framework, but it works fine for what we need.
Could this possibly be of interest to add to the github project of spine? I can see this being useful for a lot of things, but might be a bit specific for libgdx, I'm not sure if the other frameworks spine supports have anything like groups.
The GroupAttachment class looks like this:
package com.esotericsoftware.spine.attachments;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.esotericsoftware.spine.Bone;
import com.esotericsoftware.spine.Skeleton;
import com.esotericsoftware.spine.Slot;
/**
* Class for using a libgdx group as a spine attachment
*
* @author Kristoffer la Cour - Game Made Studio
*/
public class GroupAttachment extends Attachment {
private Group group;
public GroupAttachment(String name) {
super(name);
}
public Group getGroup() {
return group;
}
public void setGroup(Group label) {
this.group = label;
}
public void updatePlacement(Slot slot, boolean premultipliedAlpha) {
Skeleton skeleton = slot.getSkeleton();
Bone bone = slot.getBone();
setX(bone.getWorldX() + skeleton.getX());
setY(bone.getWorldY() + skeleton.getY());
setScaleX(bone.getWorldScaleX());
setScaleY(bone.getWorldScaleY());
setRotation(bone.getWorldRotation());
group.setColor(slot.getColor());
}
public float getX () {
return group.getX();
}
public void setX (float x) {
group.setX(x);
}
public float getY () {
return group.getY();
}
public void setY (float y) {
group.setY(y);
}
public float getScaleX () {
return group.getScaleX();
}
public void setScaleX (float scaleX) {
group.setScaleX(scaleX);
}
public float getScaleY () {
return group.getScaleY();
}
public void setScaleY (float scaleY) {
group.setScaleY(scaleY);
}
public float getRotation () {
return group.getRotation();
}
public void setRotation (float rotation) {
group.setRotation(rotation);
}
public float getWidth () {
return group.getWidth();
}
public void setWidth (float width) {
group.setWidth(width);;
}
public float getHeight () {
return group.getHeight();
}
public void setHeight (float height) {
group.setHeight(height);;
}
public Color getColor () {
return group.getColor();
}
}
And my edit to the SkeletonRenderer is in the draw function, where i added an else if statement at the bottom to handle the group attachment:
public void draw (SpriteBatch batch, Skeleton skeleton) {
boolean premultipliedAlpha = this.premultipliedAlpha;
int srcFunc = premultipliedAlpha ? GL11.GL_ONE : GL11.GL_SRC_ALPHA;
batch.setBlendFunction(srcFunc, GL11.GL_ONE_MINUS_SRC_ALPHA);
boolean additive = false;
Array<Slot> drawOrder = skeleton.drawOrder;
for (int i = 0, n = drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i);
Attachment attachment = slot.attachment;
if (attachment instanceof RegionAttachment) {
RegionAttachment regionAttachment = (RegionAttachment)attachment;
regionAttachment.updateWorldVertices(slot, premultipliedAlpha);
float[] vertices = regionAttachment.getWorldVertices();
if (slot.data.getAdditiveBlending() != additive) {
additive = !additive;
if (additive)
batch.setBlendFunction(srcFunc, GL11.GL_ONE);
else
batch.setBlendFunction(srcFunc, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
batch.draw(regionAttachment.getRegion().getTexture(), vertices, 0, 20);
} else if(attachment instanceof GroupAttachment) {
GroupAttachment groupAttachment = (GroupAttachment)attachment;
groupAttachment.updatePlacement(slot, premultipliedAlpha);
groupAttachment.getGroup().draw(batch, 1);
}
}
}
I then add a group by replacing the attachment on a slot like this:
GroupAttachment groupAttachment = new GroupAttachment(getSkeleton().findSlot(slotName).getAttachment().getName());
Group group = new Group();
group.addActor(label);
groupAttachment.setGroup(group);
getSkeleton().getSkin().addAttachment(getSkeleton().findSlotIndex(slotName), slotName, groupAttachment);
getSkeleton().findSlot(slotName).setAttachment(groupAttachment);
I'm not sure if i use the addAttachment function correctly, but it works for us.