Jump to content

GameObject update never called?


Shalmak
 Share

Recommended Posts

I am creating a custom game object, specifically a class that extends Phaser.Physics.Arcade.Sprite.

In the preUpdate method I put all the logic that should happen for every game step, and this seems to work fine.

But according to the documentation, it seems like this logic should be in the update method.

When I add an update method to my class, it never gets called.

GameObject's update method doesn't seem to be called either.

Can someone please explain how (and why) to override the update method rather then preUpdate?

Link to comment
Share on other sites

Unlike Phaser 2, Phaser 3 requires that you call each objects update method. This can be done one of two ways:

1. Add the object to a group which has the property runChildUpdate property set to true.

2. Call the objects update method in the scene's update method:

var SceneA = new Phaser.Class({

    Extends: Phaser.Scene,

    initialize:

    function SceneA ()
    {
        Phaser.Scene.call(this, { key: 'sceneA' });

    },

    create: function ()
    {
       this.customObject = new customObject(x, y, etc);
    },

    update: function (time, delta)
    {
        this.customObject.update(time, delta);
    }

});

 

Link to comment
Share on other sites

I think it's fine to override the preUpdate method if you like. A lot of the examples do this. Nb.

  • It won't work for Game Objects without a preUpdate method (e.g., Image).
  • You have to remember to call the parent class's preUpdate method.
  • preUpdate comes a little earlier than update. For instance, with ArcadeSprite, preUpdate runs right before the physics step whereas update runs right after. For a lot of cases I'd guess it doesn't make a big difference, though.
Link to comment
Share on other sites

8 minutes ago, samme said:

preUpdate comes a little earlier than update. For instance, with ArcadeSprite, preUpdate runs right before the physics step whereas update runs right after. For a lot of cases I'd guess it doesn't make a big difference, though.

I think it could really help a developer to know more about these steps (like preupdate, physics, update, and anything else) - what each one does, their order etc.

Is this documented anywhere?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...