random frame on animation

Recommended Posts


in my create I have:

            key: '_chestwaiting',
            frames: this.anims.generateFrameNames('chestwaiting'),
            repeat: -1

then later with a for cycle I do:

for (let i = 0; i < 3; i++) {
            chests[i] = this.add.sprite(this.chests_positions[i].x, this.chests_positions[i].y).setOrigin(0, 0).play('_chestwaiting')

but this way all 3 are synchronized waving up and down, so I wonder if there is a way to make them start with a random frame... hope I've been clear.

Thanks a lot

Share this post

Link to post
Share on other sites

^ What samme said.

let random = Phaser.Math.Between(range, maxRange); //put numbers here.

chests[i] = this.add.sprite(this.chests_positions[i].x, this.chests_positions[i].y).setOrigin(0, 0).play('_chestwaiting', ignoreifPlayingBool, random)


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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.