Hey guys,
First of all, thank you in advance for your help.
I’m dealing with an issue I can’t wrap my head around, while using group pooling and creating multiple instances with {active: false,visible: false} properties, the invisible sprites are still interactable and appear in the debug view as active bodies - SS below.
It must be something in the construction of the class, but I can’t see it. Any help would be appreciated.
This is the group class:
export class PlayerBullets extends Phaser.Physics.Arcade.Group {
constructor(scene) {
super(scene.physics.world, scene);
// Initialize the group
this.createMultiple({
classType: bullet, // This is the class we create just below
frameQuantity: 10, // Create 10 instances in the pool
active: false,
visible: false,
enable: false,
key: 'SmallBlue',
})
}
firebullet (x,y) {
let bullet = this.getFirstDead(false);
if (bullet) {
bullet.fire(x, y);
bullet.setVelocity(0, -260);
bullet.setScale(0.5);
bullet.setCircle(12, +52, +48);
bullet.angle = -90
}
}
}
And here is the custom class that the group uses:
class bullet extends Phaser.Physics.Arcade.Sprite {
constructor(scene, x, y, texture) {
super(scene, x, y, texture);
}
preUpdate(time,delta) {
let { width, height } = this.scene.sys.game.canvas;
super.preUpdate(time.delta);
if ( 0 > this.y || this.y > height || 0 > this.x || this.x > width ) {
this.setActive(false);
this.setVisible(false);
}
}
fire(x,y) {
this.body.reset(x, y);
this.setActive(true);
this.setVisible(true);
}
}