Move group as a whole, move all sprites by the same offset?

In Phaser 2 it was possible to add sprites to a group and then move the group as a whole. All the sprite positions in the group were relative to the group position, so if the group is at pos 0,0 and sprite is at 40,30 it works as normal. But if you then moved the group 100 pixels to left, all sprites in group would move, while each individual sprite position was unchanged. So the sprite would be on screen at position 140,30 while its x,y position was still 40,30.

sprite_group

It seems that this works differently in Phaser 3, is something like that still possible? The group position x,y can be set at create but when I try to change the value it seems that group.x and group.y are undefined. I’ve looked here and here but couldn’t find it.

Also, I’ve used the group scale effect in Phaser2, which was really useful. You could set the anchor of the group and then scaling the group would scale all sprites around that origin point, which was helpful for some animation effects.

Groups behave in entirely different ways in Phaser 2 and Phaser 3. The latter has a flat display list and Groups are essentially arrays of Game Objects. The properties in the constructor’s configuration object are used only to create the Group’s initial children. If you want to operate on a Group’s children, you can look at the Phaser.Actions namespace.

Alternatively, Phaser 3 also offers Containers - Game Objects which behave like Phaser 2’s Groups. If you want to treat multiple Game Objects as one whole, Containers are the easiest solution.

1 Like

Thanks, didn’t know about the container class, that’s exactly what I was looking for. :slight_smile: :+1: The scaling effect also works using this.