From 5fb65ef04d1ff8f697cae5c5c9b4cf37b0bacf06 Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Mon, 19 Feb 2024 22:24:29 -0600 Subject: [PATCH] feat: Add use bounds setting to graphics group --- src/engine/Graphics/GraphicsGroup.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/engine/Graphics/GraphicsGroup.ts b/src/engine/Graphics/GraphicsGroup.ts index 29252f1d4..27898e693 100644 --- a/src/engine/Graphics/GraphicsGroup.ts +++ b/src/engine/Graphics/GraphicsGroup.ts @@ -12,6 +12,14 @@ export interface GraphicsGroupingOptions { export interface GraphicsGrouping { offset: Vector; graphic: Graphic; + /** + * Optionally disable this graphics bounds as part of group calculation, default true + * if unspecified + * + * You may want to do this if you're using text because their bounds will affect + * the centering of the whole group + */ + useBounds?: boolean; } export class GraphicsGroup extends Graphic implements HasTick { @@ -44,9 +52,12 @@ export class GraphicsGroup extends Graphic implements HasTick { if (member instanceof Graphic) { bb = member.localBounds.combine(bb); } else { - const { graphic, offset: pos } = member; + const { graphic, offset: pos, useBounds } = member; + const shouldUseBounds = useBounds === undefined ? true : useBounds; if (graphic) { - bb = graphic.localBounds.translate(pos).combine(bb); + if (shouldUseBounds) { + bb = graphic.localBounds.translate(pos).combine(bb); + } } else { this._logger.warnOnce(`Graphics group member has an null or undefined graphic, member definition: ${JSON.stringify(member)}.`); }