Sign in to follow this  
eddieone

ES6 + Phaser is great

Recommended Posts

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.