|
@@ -30,18 +30,20 @@
|
|
|
|
|
|
package com.esotericsoftware.spine.utils;
|
|
|
|
|
|
-import com.badlogic.gdx.graphics.Color;
|
|
|
-import com.badlogic.gdx.graphics.g2d.Batch;
|
|
|
-import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
|
import com.esotericsoftware.spine.AnimationState;
|
|
|
import com.esotericsoftware.spine.Skeleton;
|
|
|
import com.esotericsoftware.spine.SkeletonRenderer;
|
|
|
|
|
|
+import com.badlogic.gdx.graphics.Color;
|
|
|
+import com.badlogic.gdx.graphics.g2d.Batch;
|
|
|
+import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
|
+
|
|
|
/** A scene2d actor that draws a skeleton. */
|
|
|
public class SkeletonActor extends Actor {
|
|
|
private SkeletonRenderer renderer;
|
|
|
private Skeleton skeleton;
|
|
|
AnimationState state;
|
|
|
+ private boolean resetBlendFunction = true;
|
|
|
|
|
|
/** Creates an uninitialized SkeletonActor. The renderer, skeleton, and animation state must be set before use. */
|
|
|
public SkeletonActor () {
|
|
@@ -61,6 +63,9 @@ public class SkeletonActor extends Actor {
|
|
|
}
|
|
|
|
|
|
public void draw (Batch batch, float parentAlpha) {
|
|
|
+ int blendSrc = batch.getBlendSrcFunc(), blendDst = batch.getBlendDstFunc();
|
|
|
+ int blendSrcAlpha = batch.getBlendSrcFuncAlpha(), blendDstAlpha = batch.getBlendDstFuncAlpha();
|
|
|
+
|
|
|
Color color = skeleton.getColor();
|
|
|
float oldAlpha = color.a;
|
|
|
skeleton.getColor().a *= parentAlpha;
|
|
@@ -68,6 +73,8 @@ public class SkeletonActor extends Actor {
|
|
|
skeleton.setPosition(getX(), getY());
|
|
|
renderer.draw(batch, skeleton);
|
|
|
|
|
|
+ if (resetBlendFunction) batch.setBlendFunctionSeparate(blendSrc, blendDst, blendSrcAlpha, blendDstAlpha);
|
|
|
+
|
|
|
color.a = oldAlpha;
|
|
|
}
|
|
|
|
|
@@ -94,4 +101,14 @@ public class SkeletonActor extends Actor {
|
|
|
public void setAnimationState (AnimationState state) {
|
|
|
this.state = state;
|
|
|
}
|
|
|
+
|
|
|
+ public boolean getResetBlendFunction () {
|
|
|
+ return resetBlendFunction;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** If false, the blend function will be left as whatever {@link SkeletonRenderer#draw(Batch, Skeleton)} set. This can reduce
|
|
|
+ * batch flushes in some cases, but means other rendering may need to first set the blend function. Default is true. */
|
|
|
+ public void setResetBlendFunction (boolean resetBlendFunction) {
|
|
|
+ this.resetBlendFunction = resetBlendFunction;
|
|
|
+ }
|
|
|
}
|