Using Group to spawn Objects randomly

As in the Phaser 3 game tutorial i want to use the StarGroup to spawn objects with a random x and a locked y.

I don’t know how to get the children objects to work properly.

this is the parent group:

 this.bananaGroup = this.physics.add.group(
        {
          key: 'banana',
          // repeat: 1,
          setScale:{ x: 0.3, y: 0.3 },
          setSize: {x: 20, y: 20},
          setXY: { x: (Phaser.Math.Between(150, 800)), y: 0, stepX: (Phaser.Math.Between(100, 400)) }
        }
      );

and the same math i used there (without step x) i want to use on the child group.

 if (this.bananaGroup.countActive(true) === 0)
       {
            this.bananaGroup.children.iterate(function (child) {

            child.enableBody(true, child.x, 0, true, true);

i want to change child.enableBody that way, that it shows the body again and spawns the objects the same way the parent object did.

I think you’ll have to store the initial setXY values.
Maybe add a createCallback (or createMultipleCallback) (Group - Notes of Phaser 3)

{
    createCallback: callback,
}

and then

var callback = function(gameObject) {
    gameObject.initialX = gameObject.x;
}