Bladeren bron

[ts, csharp] Revert RegionAttachment#UpdateOffset from csharp to ts, instead use ts code.

#1889
Nathan Sweet 4 jaren geleden
bovenliggende
commit
0347c262e0

+ 6 - 10
spine-csharp/src/Attachments/RegionAttachment.cs

@@ -76,16 +76,12 @@ namespace Spine {
 		}
 		}
 
 
 		public void UpdateOffset () {
 		public void UpdateOffset () {
-			float width = this.width, height = this.height;
-			float scaleX = this.scaleX, scaleY = this.scaleY;
-			float localX2 = width * 0.5f;
-			float localY2 = height * 0.5f;
-			float localX = (-localX2 + regionOffsetX / regionOriginalWidth * width) * scaleX;
-			float localY = (-localY2 + regionOffsetY / regionOriginalHeight * height) * scaleY;
-			localX2 -= (regionOriginalWidth - regionOffsetX - regionWidth) / regionOriginalWidth * width;
-			localY2 -= (regionOriginalHeight - regionOffsetY - regionHeight) / regionOriginalHeight * height;
-			localX2 *= scaleX;
-			localY2 *= scaleY;
+			float regionScaleX = width / regionOriginalWidth * scaleX;
+			float regionScaleY = height / regionOriginalHeight * scaleY;
+			float localX = -width / 2 * scaleX + regionOffsetX * regionScaleX;
+			float localY = -height / 2 * scaleY + regionOffsetY * regionScaleY;
+			float localX2 = localX + regionWidth * regionScaleX;
+			float localY2 = localY + regionHeight * regionScaleY;
 			float cos = MathUtils.CosDeg(this.rotation);
 			float cos = MathUtils.CosDeg(this.rotation);
 			float sin = MathUtils.SinDeg(this.rotation);
 			float sin = MathUtils.SinDeg(this.rotation);
 			float x = this.x, y = this.y;
 			float x = this.x, y = this.y;

+ 6 - 10
spine-ts/core/src/attachments/RegionAttachment.ts

@@ -79,16 +79,12 @@ module spine {
 		/** Calculates the {@link #offset} using the region settings. Must be called after changing region settings. */
 		/** Calculates the {@link #offset} using the region settings. Must be called after changing region settings. */
 		updateOffset () : void {
 		updateOffset () : void {
 			let region = this.region;
 			let region = this.region;
-			let width = this.width, height = this.height;
-			let scaleX = this.scaleX, scaleY = this.scaleY;
-			let localX2 = width * 0.5;
-			let localY2 = height * 0.5;
-			let localX = (-localX2 + region.offsetX / region.originalWidth * width) * scaleX;
-			let localY = (-localY2 + region.offsetY / region.originalHeight * height) * scaleY;
-			localX2 -= (region.originalWidth - region.offsetX - region.width) / region.originalWidth * width;
-			localY2 -= (region.originalHeight - region.offsetY - region.height) / region.originalHeight * height;
-			localX2 *= scaleX;
-			localY2 *= scaleY;
+			let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
+			let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
+			let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
+			let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
+			let localX2 = localX + this.region.width * regionScaleX;
+			let localY2 = localY + this.region.height * regionScaleY;
 			let radians = this.rotation * Math.PI / 180;
 			let radians = this.rotation * Math.PI / 180;
 			let cos = Math.cos(radians);
 			let cos = Math.cos(radians);
 			let sin = Math.sin(radians);
 			let sin = Math.sin(radians);