瀏覽代碼

[libgdx] Don't mix from uninitialized vertices. Clear vertices instead of leaving them in current state before first key when alpha is 1. More efficient clearing of deform before first key.

NathanSweet 8 年之前
父節點
當前提交
33d4c60ac7
共有 1 個文件被更改,包括 10 次插入14 次删除
  1. 10 14
      spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java

+ 10 - 14
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java

@@ -862,8 +862,6 @@ public class Animation {
 
 
 	/** Changes a slot's {@link Slot#getAttachmentVertices()} to deform a {@link VertexAttachment}. */
 	/** Changes a slot's {@link Slot#getAttachmentVertices()} to deform a {@link VertexAttachment}. */
 	static public class DeformTimeline extends CurveTimeline {
 	static public class DeformTimeline extends CurveTimeline {
-		static private float[] zeros = new float[64];
-
 		int slotIndex;
 		int slotIndex;
 		VertexAttachment attachment;
 		VertexAttachment attachment;
 		private final float[] frames; // time, ...
 		private final float[] frames; // time, ...
@@ -923,28 +921,24 @@ public class Animation {
 			if (!(slotAttachment instanceof VertexAttachment) || !((VertexAttachment)slotAttachment).applyDeform(attachment)) return;
 			if (!(slotAttachment instanceof VertexAttachment) || !((VertexAttachment)slotAttachment).applyDeform(attachment)) return;
 
 
 			FloatArray verticesArray = slot.getAttachmentVertices();
 			FloatArray verticesArray = slot.getAttachmentVertices();
+			if (verticesArray.size == 0) alpha = 1;
+
 			float[][] frameVertices = this.frameVertices;
 			float[][] frameVertices = this.frameVertices;
 			int vertexCount = frameVertices[0].length;
 			int vertexCount = frameVertices[0].length;
-			float[] vertices = verticesArray.setSize(vertexCount);
 
 
 			float[] frames = this.frames;
 			float[] frames = this.frames;
 			if (time < frames[0]) { // Time is before first frame.
 			if (time < frames[0]) { // Time is before first frame.
 				VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
 				VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
 				switch (pose) {
 				switch (pose) {
 				case setup:
 				case setup:
-					float[] zeroVertices;
-					if (vertexAttachment.getBones() == null) {
-						// Unweighted vertex positions (setup pose).
-						zeroVertices = vertexAttachment.getVertices();
-					} else {
-						// Weighted deform offsets (zeros).
-						zeroVertices = zeros;
-						if (zeroVertices.length < vertexCount) zeros = zeroVertices = new float[vertexCount];
-					}
-					System.arraycopy(zeroVertices, 0, vertices, 0, vertexCount);
+					verticesArray.clear();
 					return;
 					return;
 				case current:
 				case current:
-					if (alpha == 1) break;
+					if (alpha == 1) {
+						verticesArray.clear();
+						return;
+					}
+					float[] vertices = verticesArray.setSize(vertexCount);
 					if (vertexAttachment.getBones() == null) {
 					if (vertexAttachment.getBones() == null) {
 						// Unweighted vertex positions.
 						// Unweighted vertex positions.
 						float[] setupVertices = vertexAttachment.getVertices();
 						float[] setupVertices = vertexAttachment.getVertices();
@@ -960,6 +954,8 @@ public class Animation {
 				return;
 				return;
 			}
 			}
 
 
+			float[] vertices = verticesArray.setSize(vertexCount);
+
 			if (time >= frames[frames.length - 1]) { // Time is after last frame.
 			if (time >= frames[frames.length - 1]) { // Time is after last frame.
 				float[] lastVertices = frameVertices[frames.length - 1];
 				float[] lastVertices = frameVertices[frames.length - 1];
 				if (alpha == 1) {
 				if (alpha == 1) {