Jump to content

animation not destructed


giorg
 Share

Recommended Posts

Hi,

this function:

playWin(idx) {
        console.log(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 () {
            answer.destroy()
            c.destroy();
        }, 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...

thanks

Screen Shot 2018-09-28 at 09.33.02.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...