Skip to content

Commit

Permalink
feat: Add use bounds setting to graphics group
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Feb 20, 2024
1 parent 6bbdc75 commit 5fb65ef
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/engine/Graphics/GraphicsGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)}.`);
}
Expand Down

0 comments on commit 5fb65ef

Please sign in to comment.