Hi guys, I’m newbie, sorry for stupid questions, but…
I have a BombItem
class and a BombsList
class which is a collection of bombs.
class BombItem extends Phaser.Physics.Arcade.Image {
constructor(config) {
super(config.scene, config.x, config.y, config.key);
this.scene.physics.world.enable(this);
this.scene.add.existing(this);
// !! -> Not working (overwritten) if added to the group:
// this.setBounce(1);
// this.setCollideWorldBounds(true);
// this.setVelocity(Phaser.Math.Between(-200, 200), 20);
}
}
class BombsList extends Phaser.Physics.Arcade.Group {
constructor(config) {
super(config.scene.physics.world, config.scene);
// !! -> Overwrite defaults. Is that a correct way?
this.defaults.setBounce = 1;
this.defaults.setCollideWorldBounds = true;
// this.defaults.setVelocityX = Phaser.Math.Between(-200, 200);
this.defaults.setVelocityY = 20;
}
addBomb(x, y) {
const newBomb = new Bomb({scene: this.scene, x, y, key: 'bomb'});
// newBomb.setVelocityX = Phaser.Math.Between(-200, 200); // !! -> not working
this.add(newBomb);
}
}
I’m trying to update the properties like (setBounce
and setCollideWorldBounds
) of the Group by using the this.defaults
access. So basically I just overwrite defaults. It works, but I’m not sure that this is the correct way to do it. Maybe there are some methods I can call to update the required properties? (There are no info about this in the documentation)
And the second question, how to set the velocity (or other property) to a newly created Bomb class inside my addBomb
method?
Thank you!