Shalmak 0 Report post Posted November 5, 2018 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? Share this post Link to post Share on other sites
B3L7 23 Report post Posted November 5, 2018 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); } }); 1 1 Olf and Shalmak reacted to this Share this post Link to post Share on other sites
Shalmak 0 Report post Posted November 5, 2018 Got it, thanks. So the remaining question is why - what would be the difference between using update as you suggested versus putting the same logic in preUpdate? Share this post Link to post Share on other sites
B3L7 23 Report post Posted November 5, 2018 I've never used the preUpdate method. According to the API: Quote The pre-update step. Handles Game Objects that are pending insertion to and removal from the list. Share this post Link to post Share on other sites
samme 700 Report post Posted November 5, 2018 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. 1 1 Shalmak and B3L7 reacted to this Share this post Link to post Share on other sites
Shalmak 0 Report post Posted November 5, 2018 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? Share this post Link to post Share on other sites
rex 13 Report post Posted November 6, 2018 Here , and here is a simple note of phaser3's main loop. 2 B3L7 and samme reacted to this Share this post Link to post Share on other sites