Here is a group that contains left shelf and right shelf. and inside the left shelf there is left flag and inside of right shelf there is right flag.
Phaser.Display.Align.In.RightCenter(this.leftFlag, this.leftShelf).setOrigin(0,0.5);
Phaser.Display.Align.In.LeftCenter(this.rightFlag, this.rightShelf).setOrigin(0,0.5);
I want to move them all as a group:
const groupShelf = this.physics.add.group({
defaultKey: 'row',
bounceX: 1,
});
groupShelf.add(this.leftFlag);
groupShelf.add(this.rightFlag);
groupShelf.add(this.leftShelf);
groupShelf.add(this.rightShelf);
groupShelf.setVelocityX(100);
and i add two lines at the left and right side of the screen for checking collision with leftFlag and rightFlag to change the movement direction and avoid to exit shelves from the screen.
this.lineLeft = this.add.line(0,0, 0,0, 0, game.config.height, 0xff00ff).setOrigin(0);
this.lineLeft.setLineWidth(5);
this.physics.add.existing(this.lineLeft);
this.lineRight = this.add.line(0,0, game.config.width,0, game.config.width, game.config.height, 0xff00ff).setOrigin(0);
this.lineRight.setLineWidth(5);
this.physics.add.existing(this.lineRight);
this.physics.add.collider(this.rightFlag, this.lineRight, function ()
{
console.log("Right Flag ");
groupShelf.setVelocityX(100);
});
this.physics.add.collider(this.leftFlag, this.lineLeft, function ()
{
console.log("Left Flag ");
groupShelf.setVelocityX(-100);
});
there is no error and there is no collision detection.
Thank you very much for your guidance.