I have a big problem with isPlaying property in Phaser 3 that causes a game block and an error in browser console. I have this two pieces of code in which I handle the collide between the missiles and the platforms of the game:
this.physics.add.collider(missile, platforms, () => {
if (missile && (!missile.anims.isPlaying || missile.anims.currentAnim.key !== 'missExplosion')) {
missile.setTexture('expl1');
missile.play('missExplosion');
missile.on('animationcomplete',() => {
missile.destroy();
})
}
setTimeout(() => {
keyIsDown = true;
}, 500);
});
And this one :
this.physics.add.collider(cpuMissile, platforms, () => {
if (cpuMissile && (!cpuMissile.anims.isPlaying || cpuMissile.anims.currentAnim.key !== 'cpuMissExplosion')) {
cpuMissile.setTexture('expl1');
cpuMissile.play('cpuMissExplosion');
cpuMissile.on('animationcomplete',() => {
cpuMissile.destroy();
});
}
});
The two pieces of code are very similar, in fact they do the same animation, but the first on the projectile fired by player and the second on the projectile fired by cpu. Now the problem is that after some shot the game crash and in the console browser i have this error:
Uncaught TypeError: Cannot read properties of undefined (reading 'isPlaying')
The problem indicates the two row with if-clause, but i don't understand what really cause the problem because the animation is fine for some repetitions, until the block of the game, even if I do nothing. I setup some setTimeout to prevent two animations on same sprite start in the same time, but it seem not depends on this. I hope the post is clearly, and thanks to everyone in advance!