How to create a group from atlas images

Hi,
I can create a grop members from pre loaded images. But when I try this with images from atlas… Desparation!

preload()
    {
        this.load.atlas('megaset', 'images/spritesheet_2.png', 'images/spritesheet_2.json')
    }
create()
{
      this.platforms = this.physics.add.staticGroup()
        for (let i = 0; i < 8; i++)
        {
            const x = 128 * i
           // const platformImage = this.physics.add.sprite(128 * i, 350, 'megaset').setOrigin(0, 0)
            // const platform = this.platforms.create(128 * i, 350, 'platform')
            const platform = this.platforms.create({
                //classType: this.Phaser.Physics.Arcade.Sprite,
                key: 'megaset',
                frame: 'grassHalf_mid.png',
                setXY: {
                    x: x,
                    y: 350
                }
            })
        
            console.dir(platform)
            const body = platform.body
            body.updateFromGameObject()
            console.dir(body)
        }
        // this.ground = this.add.image(128, 500, 'megaset', 'grassHalf_mid.png').setOrigin(0, 0)

}

Can anyone help me please. I don’t wanna keep separate files, it kind of makes atlas unnecessery.

Frame is the name of a sprite inside the atlas, not a png, look at the megaset.json to find the frame names

this.platforms = this.physics.add.staticGroup();
for (let i = 0; i < 8; i++) {
  const x = 128 * i
  this.platforms.create(x, 350, 'megaset').setFrame('grassHalf_mid');
}

Thank you. But actually, .png is at the end of frame names in my JSON. Name ‘megaset’ is just remainder, this is new file made with some online packer.
This works, thank you again.

I think you should not pass an object into create() method, just pass arguments, like this:

const platform = this.platforms.create(
                x,
                350,
                'megaset',
                'grassHalf_mid.png'
)

Reference: Phaser 3 API Documentation - Class: Group

Using setFrame() method will only change the visible sprite, in debug mode it will still show the border of the first frame in the atlas.

And I don’t find out the setXY parameter in the documentation (Phaser 3), so I’m not sure whether it is the problem.