Migration confusion (update, health, camera, etc.)

I’m migrating from Phaser 2 CE to Phaser 3 and I find it quite confusing. Things that I used to in Phaser 2 just don’t exist or works differently.

  1. The scene update method doesn’t call the updates of game objects. Now I need to call them manually which doesn’t feel right. Or am I supposed to call update() for all my objects?

  2. If I want to use Arcade, do I need to extend Phaser.GameObjects.Sprite or Phaser.Physics.Arcade.Sprite? If I created an instance of my sprite, should I add it with scene.add.existing() or scene.physics.add.existing() or both?

  3. I used to sprites having health/damage management by default. In Phaser 2, I have properties/methods like alive, health, damage(), kill(). It made many things easy. Phaser 3 seems to not have these members. Was this feature completely removed from Phaser 3, or is there a way to access it?

  4. In Phaser 2 it was very easy to make the camera follow the player with game.camera.follow(). Now I have scene.cameras.main.startFollow(), but when I use this, I get a blank canvas. What is the proper way of doing this?

phaser3-faq covers some of these in detail.

  1. The “automatic” way would be to use a group with runChildUpdate, and there are some alternatives.

  2. You could extend either but only Arcade.Sprite has all the relevant methods. If you use scene.add.existing() (instead of a factory method) then you should use scene.physics.add.existing() as well.

  3. It’s not in Phaser but I recommend phaser-component-health :smiley:.

  4. Camera follow should work nearly the same.

@samme Thank you very much, it helped a lot!

  1. What if I add the sprite to the scene directly, not into a group? Well, runChildUpdate doesn’t work, but alternatively I could add an event handler for update:
    this.events.on('update', player.update, player);
    But if I need to have a group for using the more convenient runChildUpdate, it’s not a big deal either.

  2. That worked perfectly! PhaserHealth adds very similar functionality than it was present in Phaser 2 (albeit not entirely the same, there are some notable differences, but it’s quite fine).

  3. The mistake I made is that I also need to call scene.cameras.main.setBounds() before startFollow() for it to work.

Meanwhile I got an additional question.

  1. I want to have static text on the canvas that is not affected by camera movements. In Phaser 2, the solution was to add the text to the stage (game.stage); but it seems there is no stage in Phaser 3. I found a FAQ entry that may probably apply here: How can I make a game object stay the same size when the camera zooms?. My situation is not entirely the same because I don’t need to zoom, just keep game objects at a fixed position on the canvas, though I’m not sure if it makes any difference regarding the solution. So do I need to create another scene to display fixed text or is there an easier way?
1 Like
  1. For this you just use

    sprite.setScrollFactor(0)