mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-26 11:41:23 +08:00
[libgdx] Option to reset blend function.
This commit is contained in:
parent
643a1cb2aa
commit
4e5e82502b
@ -30,18 +30,20 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine.utils;
|
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.AnimationState;
|
||||||
import com.esotericsoftware.spine.Skeleton;
|
import com.esotericsoftware.spine.Skeleton;
|
||||||
import com.esotericsoftware.spine.SkeletonRenderer;
|
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. */
|
/** A scene2d actor that draws a skeleton. */
|
||||||
public class SkeletonActor extends Actor {
|
public class SkeletonActor extends Actor {
|
||||||
private SkeletonRenderer renderer;
|
private SkeletonRenderer renderer;
|
||||||
private Skeleton skeleton;
|
private Skeleton skeleton;
|
||||||
AnimationState state;
|
AnimationState state;
|
||||||
|
private boolean resetBlendFunction = true;
|
||||||
|
|
||||||
/** Creates an uninitialized SkeletonActor. The renderer, skeleton, and animation state must be set before use. */
|
/** Creates an uninitialized SkeletonActor. The renderer, skeleton, and animation state must be set before use. */
|
||||||
public SkeletonActor () {
|
public SkeletonActor () {
|
||||||
@ -61,6 +63,9 @@ public class SkeletonActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw (Batch batch, float parentAlpha) {
|
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();
|
Color color = skeleton.getColor();
|
||||||
float oldAlpha = color.a;
|
float oldAlpha = color.a;
|
||||||
skeleton.getColor().a *= parentAlpha;
|
skeleton.getColor().a *= parentAlpha;
|
||||||
@ -68,6 +73,8 @@ public class SkeletonActor extends Actor {
|
|||||||
skeleton.setPosition(getX(), getY());
|
skeleton.setPosition(getX(), getY());
|
||||||
renderer.draw(batch, skeleton);
|
renderer.draw(batch, skeleton);
|
||||||
|
|
||||||
|
if (resetBlendFunction) batch.setBlendFunctionSeparate(blendSrc, blendDst, blendSrcAlpha, blendDstAlpha);
|
||||||
|
|
||||||
color.a = oldAlpha;
|
color.a = oldAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,4 +101,14 @@ public class SkeletonActor extends Actor {
|
|||||||
public void setAnimationState (AnimationState state) {
|
public void setAnimationState (AnimationState state) {
|
||||||
this.state = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,18 +30,20 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine.utils;
|
package com.esotericsoftware.spine.utils;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable;
|
|
||||||
import com.esotericsoftware.spine.AnimationState;
|
import com.esotericsoftware.spine.AnimationState;
|
||||||
import com.esotericsoftware.spine.Skeleton;
|
import com.esotericsoftware.spine.Skeleton;
|
||||||
import com.esotericsoftware.spine.SkeletonRenderer;
|
import com.esotericsoftware.spine.SkeletonRenderer;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable;
|
||||||
|
|
||||||
/** A scene2d drawable that draws a skeleton. The animation state and skeleton must be updated each frame, or
|
/** A scene2d drawable that draws a skeleton. The animation state and skeleton must be updated each frame, or
|
||||||
* {@link #update(float)} called each frame. */
|
* {@link #update(float)} called each frame. */
|
||||||
public class SkeletonDrawable extends BaseDrawable {
|
public class SkeletonDrawable extends BaseDrawable {
|
||||||
private SkeletonRenderer renderer;
|
private SkeletonRenderer renderer;
|
||||||
private Skeleton skeleton;
|
private Skeleton skeleton;
|
||||||
AnimationState state;
|
AnimationState state;
|
||||||
|
private boolean resetBlendFunction = true;
|
||||||
|
|
||||||
/** Creates an uninitialized SkeletonDrawable. The renderer, skeleton, and animation state must be set before use. */
|
/** Creates an uninitialized SkeletonDrawable. The renderer, skeleton, and animation state must be set before use. */
|
||||||
public SkeletonDrawable () {
|
public SkeletonDrawable () {
|
||||||
@ -59,9 +61,14 @@ public class SkeletonDrawable extends BaseDrawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw (Batch batch, float x, float y, float width, float height) {
|
public void draw (Batch batch, float x, float y, float width, float height) {
|
||||||
|
int blendSrc = batch.getBlendSrcFunc(), blendDst = batch.getBlendDstFunc();
|
||||||
|
int blendSrcAlpha = batch.getBlendSrcFuncAlpha(), blendDstAlpha = batch.getBlendDstFuncAlpha();
|
||||||
|
|
||||||
skeleton.setPosition(x, y);
|
skeleton.setPosition(x, y);
|
||||||
skeleton.updateWorldTransform();
|
skeleton.updateWorldTransform();
|
||||||
renderer.draw(batch, skeleton);
|
renderer.draw(batch, skeleton);
|
||||||
|
|
||||||
|
if (resetBlendFunction) batch.setBlendFunctionSeparate(blendSrc, blendDst, blendSrcAlpha, blendDstAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkeletonRenderer getRenderer () {
|
public SkeletonRenderer getRenderer () {
|
||||||
@ -87,4 +94,14 @@ public class SkeletonDrawable extends BaseDrawable {
|
|||||||
public void setAnimationState (AnimationState state) {
|
public void setAnimationState (AnimationState state) {
|
||||||
this.state = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user