eddieone Posted November 28, 2018 Share Posted November 28, 2018 Here's the scenario, 1 to 5 animals attack the boss, then the boss attacks each animal. This is the code using async/wait await this.attackBoss(this.seat1); if (this.seats.length >= 2) { await this.attackBoss(this.seat2); } if (this.seats.length >= 3) { await this.attackBoss(this.seat3); } if (this.seats.length >= 4) { await this.attackBoss(this.seat4); } if (this.seats.length >= 5) { await this.attackBoss(this.seat5); } await this.bossAttack(this.seat1); if (this.seats.length >= 2) { await this.bossAttack(this.seat2); } if (this.seats.length >= 3) { await this.bossAttack(this.seat3); } if (this.seats.length >= 4) { await this.bossAttack(this.seat4); } if (this.seats.length >= 5) { await this.bossAttack(this.seat5); } The above code takes a few seconds for all the animations to complete. Using promises to end the await part once the animations finish. attackBoss(seat) { return new Promise(resolve => { this.tweens.add({ targets: seat, x: this.bossSeat.x, ease: 'Sine', duration: 500, yoyo: true, onYoyo: () => { this.bouncBoss(); }, onComplete: () => { resolve('resolved'); } }); }); } I might make a goldilocks es6 boilerplate for phaser 3. Mostly just adding async to generator babel plugin to already existing boilerplates. babel-plugin-transform-async-to-generator Befive.Info 1 Link to comment Share on other sites More sharing options...
Recommended Posts