spine中插入任意Actor
原理替换到data数据中的region
修改部分
Skin
add set region方法
public void setAttachment(Attachment attachment) {
this.attachment = attachment;
}
获取data数据,设置region
SkeletonData data = actor.getSkeleton().getData();
Skin defaultSkin = data.getDefaultSkin();
for (Skin.SkinEntry attachment : defaultSkin.getAttachments()) {
if (attachment.getName().equals("xuanq2_00")) {
attachment.setAttachment(actorAttachment);
}
}
修改renderer方法
draw方法加入
if (attachment instanceof ActorAttachment){
Actor actor = ((ActorAttachment) attachment).getActor();
Bone bone = slot.getBone();
float worldX = bone.getWorldX();
float worldY = bone.getWorldY();
actor.setOrigin(Align.center);
actor.setPosition(worldX,worldY, Align.center);
actor.setScale(bone.scaleX,bone.scaleY);
actor.setColor(slot.getColor());
actor.draw(batch,skeleton.color.a);
}
自定义ActorAttachment
import com.badlogic.gdx.scenes.scene2d.Actor;
public class ActorAttachment extends Attachment {
private Actor actor;
public ActorAttachment(String name) {
super(name);
}
public Actor getActor() {
return actor;
}
public ActorAttachment(ActorAttachment actorAttachment) {
super(actorAttachment);
this.actor = actorAttachment.actor;
}
public void setActor(Actor actor) {
this.actor = actor;
}
@Override
public Attachment copy() {
return new ActorAttachment(this);
}
}
理论上可以支持任意……