Hello, I try to create like arcanoid game. I create ball
this.ball = this.add.circle(200, 100, 10, 0xffffff, 1);
if (this.ball) {
this.physics.add.existing(this.ball);
this.ball.body.setVelocity(100, 300);
this.ball.body.setBounce(1.2, 1.2);
this.ball.body.setMaxVelocity(900, 900);
this.ball.body.setCollideWorldBounds(true, 1, 1);
}
than in side of loop brick:
const newBrick = this.add.rectangle(brick.x, brick.y, 200, 10, 0xffffff, 1);
Now i would like to implement some hit points and type of brick:
newBrick.customOptions = {type: brick.type, hp: brick.hp};
Now i try to implement collision in loop:
this.bricks?.forEach(brick => {
this.physics.add.collider(brick, this.ball, e => {
brick.customOptions.hp -= 1;
console.log(brick.customOptions.hp);
if (brick.customOptions.hp <= 0) {
brick.destroy();
}
});
});
But its seems to be not good that for every element i have to implement collider, also its trigger to often.
And my question is how to implements function like this ?