Jump to content

animation not destructed


Recommended Posts


this function:

playWin(idx) {
        let c = this.anims.create({
            key: '_win',
            frames: this.anims.generateFrameNames('win', {
                start: 0,
                end: 24,
                prefix: 's4b2win_',
                zeroPad: 4
            repeat: 0,

        let answer = this.add.sprite(bonusplay_results[idx].x, bonusplay_results[idx].y).setOrigin(0, 0).play('_win');
        setTimeout(function () {
        }, 2000);

is called every time the user click on a certain point... the first time works perfectly the second I get the error: Invalid Animation Key, or Key already in use: _win

what am I doing wrong?

thanks a lot

Link to comment
Share on other sites

1 hour ago, rich said:

Usually, you create all the animations you need when the game loads, then just play them as required.

let c = this.anims.create({
            key: '_win',

@giorg As rich already said, you have declared the Animation Key '_win', which you cannot repeat. Make sure you declare each Animation Key only 1x in your game. If you try to declare it again at a later point it throws the error you are seeing now. Whatever is calling your playWin() function is calling it multiple times, consequently declaring the Animation Key '_win' multiple times.

Link to comment
Share on other sites

@rich because that animation is too quick, I need it to disappear but if I just set hideOnComplete it disappear too quickly... pls see attachment:  when user clicks a diamond, there is an animation on the diamond itself, which disappears, then an animation with written "Win" should appear on top of disappeared diamond.

only x and y are changing every time this animation appears, so I wanted to isolate it in a function to call every click...


Screen Shot 2018-09-28 at 09.33.02.png

Link to comment
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.
  • Create New...