com.uwsoft.editor.renderer.actor.SpineActor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of overlap2d-runtime-libgdx Show documentation
Show all versions of overlap2d-runtime-libgdx Show documentation
overlap2d-runtime-libgdx provides functionality to load, manipulate and render scenes generated by Overlap2D.
package com.uwsoft.editor.renderer.actor;
import java.lang.reflect.InvocationTargetException;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Array;
import com.uwsoft.editor.renderer.data.Essentials;
import com.uwsoft.editor.renderer.data.SpineVO;
import com.uwsoft.editor.renderer.spine.SpineDataHelper;
import com.uwsoft.editor.renderer.spine.SpineReflectionHelper;
import com.uwsoft.editor.renderer.utils.CustomVariables;
public class SpineActor extends Actor implements IBaseItem {
public SpineVO dataVO;
public float mulX = 1f;
public float mulY = 1f;
protected int layerIndex = 0;
private boolean isLockedByLayer = false;
private CompositeItem parentItem = null;
private Essentials essentials;
private CustomVariables customVariables = new CustomVariables();
private SpineReflectionHelper spineReflectionHelper;
private SpineDataHelper spineData;
//private float minX = 0;
//private float minY = 0;
private Body body;
public SpineActor(SpineVO vo, Essentials e, CompositeItem parent) {
this(vo, e);
setParentItem(parent);
}
public SpineActor(SpineVO vo, Essentials e) {
essentials = e;
this.spineReflectionHelper = essentials.spineReflectionHelper;
dataVO = vo;
initSpine();
setX(dataVO.x);
setY(dataVO.y);
setScaleX(dataVO.scaleX);
setScaleY(dataVO.scaleY);
customVariables.loadFromString(dataVO.customVars);
this.setRotation(dataVO.rotation);
if (dataVO.zIndex < 0) dataVO.zIndex = 0;
if (dataVO.tint == null) {
setTint(new Color(1, 1, 1, 1));
} else {
setTint(new Color(dataVO.tint[0], dataVO.tint[1], dataVO.tint[2], dataVO.tint[3]));
}
}
//private void computeBoundBox() {
// skeleton.updateWorldTransform();
// minX = Float.MAX_VALUE;
// minY = Float.MAX_VALUE;
// float maxX = Float.MIN_VALUE, maxY = Float.MIN_VALUE;
// for (int i = 0, n = skeleton.getSlots().size; i < n; i++) {
// Slot slot = skeleton.getSlots().get(i);
// Attachment attachment = slot.getAttachment();
// if (attachment == null) continue;
// if (!(attachment instanceof RegionAttachment)) continue;
// RegionAttachment imageRegion = (RegionAttachment) attachment;
// imageRegion.updateWorldVertices(slot, false);
// float[] vertices = imageRegion.getWorldVertices();
// for (int ii = 0, nn = vertices.length; ii < nn; ii += 5) {
// minX = Math.min(minX, vertices[ii]);
// minY = Math.min(minY, vertices[ii + 1]);
// maxX = Math.max(maxX, vertices[ii]);
// maxY = Math.max(maxY, vertices[ii + 1]);
// }
// }
//
// setWidth(maxX - minX);
// setHeight(maxY - minY);
//}
private void initSpine() {
spineData = new SpineDataHelper();
try {
spineData.initSpine(dataVO, essentials.rm, spineReflectionHelper,mulX);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
System.out.println("Reflection problem");
e.printStackTrace();
}
// skeletonJson = new SkeletonJson(essentials.rm.getSkeletonAtlas(dataVO.animationName));
// skeletonJson.setScale(dataVO.scaleX);
// skeletonData = skeletonJson.readSkeletonData((essentials.rm.getSkeletonJSON(dataVO.animationName)));
//
// skeleton = new Skeleton(skeletonData); // Skeleton holds skeleton state (bone positions, slot attachments, etc).
// AnimationStateData stateData = new AnimationStateData(skeletonData); // Defines mixing (crossfading) between animations.
// state = new AnimationState(stateData); // Holds the animation state for a skeleton (current animation, time, etc).
//
// computeBoundBox();
//
// // todo: fix this, it's a temporary soluition
// setAnimation(skeletonData.getAnimations().get(0).getName());
setWidth(spineData.width);
setHeight(spineData.height);
}
public Array
© 2015 - 2025 Weber Informatics LLC | Privacy Policy