strivinglife Posted November 27, 2018 Share Posted November 27, 2018 I'm working on a game where I want to do some checks every minute, every five minutes, and then every some amount of seconds (1 and 5 seconds now, but that might change). Right now I'm adding the following in the main game scene: // Add a main timer that runs every second. this.time.addEvent({ delay: 1000, callback: this.doOneSecondActivities, callbackScope: this, loop: true }); // Add a timer that runs every five seconds. this.time.addEvent({ delay: 5000, callback: this.doFiveSecondActivities, callbackScope: this, loop: true }); // Add a timer that should run every minute. this.time.addEvent({ delay: 60000, callback: this.doOneMinuteActivities, callbackScope: this, loop: true }); // Add a timer that should run every five minutes. this.time.addEvent({ delay: 1000 * 60 * 5, callback: this.doFiveMinuteActivities, callbackScope: this, loop: true }); I realize that I shouldn't prematurely optimize, but I'm wondering if I'm going to end up refactoring this later, or if it's relatively safe to setup multiple timers in Phaser 3. (The other way I can think of handling this is to determine what my smallest time is and then manually keep track of the last time the various events were triggered, adding/subtracting time to determine if an interval has passed. Since the game loop can be paused, I do realize that I might still need to check against a timestamp for certain things.) Does anyone have experience with multiple timed events in Phaser 3? Link to comment Share on other sites More sharing options...
Recommended Posts