Animate Text

Hi!

I would like to animate text like this example for Phaser 2: https://phaser.io/examples/v2/text/text-with-physics where you could just say game.physics.arcade.enable([ text1, text2 ]);

I can’t find the equivalent example or functions in Phaser3. At the moment I am just using an image which says “Best time”, using code from the tutorial.

But would much prefer to use text.

    let particles = this.add.particles('red');

    this.#bestTimeEmitter = particles.createEmitter({
      speed: 100,
      scale: {start: 1, end: 0},
      blendMode: 'ADD'
    });

    let bti = this.physics.add.image(400, 100, 'best_time');

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

    this.#bestTimeEmitter.startFollow(bti)

Text would be much more flexible and hopefully speed up loading too.

Thanks!

OK I think I figured it out, by adding text to a container:

   let btt = this.add.text(0, 0, 'Best time!', {
      fontSize: '32px',
      fill: '#FF0000'
    }).setOrigin(0.5);

    let container = this.add.container(400, 100, [btt]);

    this.physics.world.enableBody(container);

    container.body.setVelocity(100, 200);
    container.body.setBounce(1, 1);
    container.body.setCollideWorldBounds(true);
1 Like