From 0347c262e02b4924ab973cbb3128a35fa7693f0e Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Thu, 10 Jun 2021 00:04:28 -0400 Subject: [PATCH] [ts, csharp] Revert RegionAttachment#UpdateOffset from csharp to ts, instead use ts code. #1889 --- spine-csharp/src/Attachments/RegionAttachment.cs | 16 ++++++---------- .../core/src/attachments/RegionAttachment.ts | 16 ++++++---------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/spine-csharp/src/Attachments/RegionAttachment.cs b/spine-csharp/src/Attachments/RegionAttachment.cs index da68b1b50..80b15abb9 100644 --- a/spine-csharp/src/Attachments/RegionAttachment.cs +++ b/spine-csharp/src/Attachments/RegionAttachment.cs @@ -76,16 +76,12 @@ namespace Spine { } 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 sin = MathUtils.SinDeg(this.rotation); float x = this.x, y = this.y; diff --git a/spine-ts/core/src/attachments/RegionAttachment.ts b/spine-ts/core/src/attachments/RegionAttachment.ts index abbbfa2b7..35e890b2a 100644 --- a/spine-ts/core/src/attachments/RegionAttachment.ts +++ b/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. */ updateOffset () : void { 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 cos = Math.cos(radians); let sin = Math.sin(radians);