giorg Posted September 27, 2018 Share Posted September 27, 2018 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 More sharing options...
rich Posted September 27, 2018 Share Posted September 27, 2018 Why setTimeout? It should really be banned from games. Why create and delete the animations every click? That feels very strange. Usually, you create all the animations you need when the game loads, then just play them as required. jamespierce 1 Link to comment Share on other sites More sharing options...
jamespierce Posted September 27, 2018 Share Posted September 27, 2018 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 More sharing options...
giorg Posted September 28, 2018 Author Share Posted September 28, 2018 @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 Link to comment Share on other sites More sharing options...
Recommended Posts