From 30abd37ee7aad7a118e10a4fcb07f7074089c0df Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Fri, 20 Sep 2024 08:18:57 -0500 Subject: [PATCH] fix: Label multiplicative opacity should use graphics opacity not text opacity --- CHANGELOG.md | 1 + src/engine/Label.ts | 4 ++-- src/spec/LabelSpec.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1d1c3486..5b1c910d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ are doing mtv adjustments during precollision. ### Fixed +- Fixed issue where `ex.Label` where setting the opacity of caused a multiplicative opacity effect when actor opacity set - Fixed issue where the `ex.Loader` would have a low res logo on small configured resolution sizes - Fixed issue where `ex.Gif` was not parsing certain binary formats correctly - Fixed issue where the boot `ex.Loader` was removing pixelRatio override diff --git a/src/engine/Label.ts b/src/engine/Label.ts index c5c36573e..80705ea20 100644 --- a/src/engine/Label.ts +++ b/src/engine/Label.ts @@ -71,11 +71,11 @@ export class Label extends Actor { } public get opacity(): number { - return this._text.opacity; + return this.graphics.opacity; } public set opacity(opacity: number) { - this._text.opacity = opacity; + this.graphics.opacity = opacity; } private _spriteFont: SpriteFont; diff --git a/src/spec/LabelSpec.ts b/src/spec/LabelSpec.ts index fb9596be1..2dae6f876 100644 --- a/src/spec/LabelSpec.ts +++ b/src/spec/LabelSpec.ts @@ -87,4 +87,15 @@ describe('A label', () => { expect((sut as any)._spriteFont).toBe(spriteFont); // expect(sut.spriteFont).toBe(spriteFont); }); + + it('can have opacity set on the label and its the same as the graphics', () => { + const label = new ex.Label({ + text: 'some text', + opacity: 0.75 + }); + + expect(label.opacity).toEqual(label.graphics.opacity); + label.opacity = 0.25; + expect(label.opacity).toEqual(label.graphics.opacity); + }); });