Przeglądaj źródła

[starling] Closes #1078, breaking change. If a skeleton requires two color tinting, you have to enable it manually via SKeletonSprite.twoColorTint = true. Skeletons with two color tinting enabled use TwoColorMeshStyle, which has a different vertex layout and shader compared to the default layout and shaders used by Starling and the spine-starling runtime. This will break your batch and add additional draw calls, use with care.

badlogic 7 lat temu
rodzic
commit
7a10d04e61

+ 1 - 0
CHANGELOG.md

@@ -26,6 +26,7 @@
  * Added support for rotated regions in texture atlas loaded via StarlingAtlasAttachmentLoader.
  * Added support for vertex effects. See `RaptorExample.as`
  * Added 'getTexture()' method to 'StarlingTextureAtlasAttachmentLoader'
+ * Breaking change: if a skeleton requires two color tinting, you have to enable it via `SkeletonSprite.twoColorTint = true`. In this case the skeleton will use the `TwoColorMeshStyle`, which internally uses a different vertex layout and shader. This means that skeletons with two color tinting enabled will break batching and hence increase the number of draw calls in your app.
 
 ## C
  * **Breaking changes**

+ 0 - 7
spine-starling/spine-starling-example/.settings/org.eclipse.core.resources.prefs

@@ -1,11 +1,4 @@
 eclipse.preferences.version=1
 encoding//src/spine/examples/TankExample.as=UTF-8
 encoding//src/spine/examples/TwoColorExample.as=UTF-8
-encoding//src/spine/starling/SkeletonAnimation.as=UTF-8
-encoding//src/spine/starling/SkeletonMesh.as=UTF-8
-encoding//src/spine/starling/SkeletonSprite.as=UTF-8
-encoding//src/spine/starling/StarlingAtlasAttachmentLoader.as=UTF-8
-encoding//src/spine/starling/StarlingTextureLoader.as=UTF-8
-encoding//src/spine/starling/TwoColorEffect.as=UTF-8
-encoding//src/spine/starling/TwoColorMeshStyle.as=UTF-8
 encoding/<project>=UTF-8

BIN
spine-starling/spine-starling-example/lib/spine-starling.swc


+ 5 - 0
spine-starling/spine-starling-example/src/spine/examples/CoinExample.as

@@ -72,6 +72,11 @@ package spine.examples {
 			skeleton.state.timeScale = 0.5;
 			skeleton.state.update(0.25);
 			skeleton.state.apply(skeleton.skeleton);
+			
+			// enable two color tinting, which breaks batching between this skeleton
+			// and other Starling objects.
+			skeleton.twoColorTint = true;
+			
 			skeleton.skeleton.updateWorldTransform();
 
 			addChild(skeleton);

+ 14 - 6
spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as

@@ -59,9 +59,9 @@ package spine.starling {
 		static private var _tempMatrix : Matrix = new Matrix();
 		static private var _tempVertices : Vector.<Number> = new Vector.<Number>(8);
 		static internal var blendModes : Vector.<String> = new <String>[BlendMode.NORMAL, BlendMode.ADD, BlendMode.MULTIPLY, BlendMode.SCREEN];
-		private var _skeleton : Skeleton;
-		public var batchable : Boolean = true;
+		private var _skeleton : Skeleton;		
 		private var _smoothing : String = "bilinear";
+		private var _twoColorTint : Boolean = false;
 		private static var clipper: SkeletonClipping = new SkeletonClipping();
 		private static var QUAD_INDICES : Vector.<uint> = new <uint>[0, 1, 2, 2, 3, 0];
 		
@@ -112,7 +112,7 @@ package spine.starling {
 							region.rendererObject = mesh = new SkeletonMesh(Image(region.rendererObject).texture);
 						if (region.rendererObject is AtlasRegion)
 							region.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(region.rendererObject).rendererObject).texture);						
-						mesh.setStyle(new TwoColorMeshStyle());					
+						if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle());					
 						indexData = mesh.getIndexData();
 						for (ii = 0; ii < indices.length; ii++)
 							indexData.setIndex(ii, indices[ii]);
@@ -136,7 +136,7 @@ package spine.starling {
 							meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(meshAttachment.rendererObject).texture);
 						if (meshAttachment.rendererObject is AtlasRegion)
 							meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(meshAttachment.rendererObject).rendererObject).texture);						
-						mesh.setStyle(new TwoColorMeshStyle());
+						if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle());
 						
 						indexData = mesh.getIndexData();
 						indicesLength = meshAttachment.triangles.length;
@@ -198,13 +198,13 @@ package spine.starling {
 						tempVertex.dark.setFromColor(tempDark);
 						vertexEffect.transform(tempVertex);
 						vertexData.colorize("color", Color.rgb(tempVertex.light.r * 255, tempVertex.light.g * 255, tempVertex.light.b * 255), tempVertex.light.a, ii, 1);
-						vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1);						
+						if (_twoColorTint) vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1);						
 						mesh.setVertexPosition(ii, tempVertex.x, tempVertex.y);
 						mesh.setTexCoords(ii, tempVertex.u, tempVertex.v);
 					}
 				} else {
 					vertexData.colorize("color", rgb, a);
-					vertexData.colorize("color2", dark);
+					if (_twoColorTint) vertexData.colorize("color2", dark);
 					for (ii = 0, iii = 0; ii < verticesCount; ii++, iii += 2) {
 						mesh.setVertexPosition(ii, worldVertices[iii], worldVertices[iii + 1]);
 						mesh.setTexCoords(ii, uvs[iii], uvs[iii + 1]);
@@ -303,5 +303,13 @@ package spine.starling {
 		public function set smoothing(smoothing : String) : void {
 			_smoothing = smoothing;
 		}
+		
+		public function get twoColorTint() : Boolean {
+			return _twoColorTint;
+		}
+		
+		public function set twoColorTint(tint : Boolean) : void {
+			_twoColorTint = tint;
+		}
 	}
 }