Skip to content

Commit

Permalink
Fix adding Group to Row
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler committed Oct 21, 2021
1 parent 6d7f50f commit f0d6f24
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/phaserObjects/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ if (Phaser.Group === undefined) {
child.y = previousNode.getBounds().y + bottomY; // eslint-disable-line
}

// Containers can't be aligned automatically
/** Containers can't be aligned automatically */
alignContainerToBottom(previousNode, child) { // eslint-disable-line
const bounds = previousNode.getBounds();
const centerX = previousNode.x + (bounds.width * 0.5);
Expand All @@ -109,17 +109,30 @@ if (Phaser.Group === undefined) {
child.y = bounds.y; // eslint-disable-line
}

alignContainerToRight(previousNode, child) { // eslint-disable-line
const rightX = previousNode.x + previousNode.width;

child.x = rightX; // eslint-disable-line
}

/** Aligns child to the last object in the group.
* @private
*/
alignNodeToPrevious(child, align, paddingX, paddingY) {
const nodes = this.getNodes();
const previousNode = nodes[nodes.length - 2];

const toGroupAlignFuncs = {
11: this.alignContainerToBottom, // Column
8: this.alignContainerToRight, // Row
};

const toGroupAlignFunc = toGroupAlignFuncs[align];

if (previousNode instanceof Phaser3Group) {
this.alignToContainerBottom(previousNode, child);
} else if (child instanceof Phaser3Group && (previousNode !== undefined)) {
this.alignContainerToBottom(previousNode, child);
toGroupAlignFunc(previousNode, child);
} else if (previousNode !== undefined) {
this.alignToMapping[align](child, previousNode, paddingX, paddingY);
}
Expand Down

0 comments on commit f0d6f24

Please sign in to comment.