Create sprite, destroy sprite and update

If the variable cat = 0 create a sprite ‘star’
If the variable cat = 1 destroy the sprite ‘star’

How can I do this in Phaser 3?

Hey You can simply modify this code sheet according to your needs

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    parent: 'phaser-example',
    physics: {
        default: 'arcade',
        arcade: {
            debug: true
        }
    },
    scene: {
        preload: preload,
        create: create
    }
};

var sprite;
var group;

var game = new Phaser.Game(config);

function preload() {
    this.load.image('mushroom', 'assets/sprites/mushroom2.png');
    this.load.image('ball', 'assets/sprites/shinyball.png');
}

function create() {
    sprite = this.physics.add.image(400, 300, 'mushroom');

    group = this.physics.add.staticGroup({
        key: 'ball',
        frameQuantity: 30,
        scale: Math.random(1, 4)
    });

    group.children.each(function (sprite) {
        sprite.setScale(Math.random(3, 8));
        sprite.setOrigin(.5)
    }, this);
 

    Phaser.Actions.PlaceOnRectangle(group.getChildren(), new Phaser.Geom.Rectangle(84, 84, 616, 416));

    group.refresh();

    sprite.setVelocity(100, 200).setBounce(1, 1).setCollideWorldBounds(true).setGravityY(200);

    this.physics.add.collider(sprite, group);
}