I want to create a reddening of the screen in a collision with an enemy, but for some reason my code does not work.
//overlap
this.physics.add.overlap(this.player, this.enemies, this.playerDamage, null, this);
//callback overlap
let overlapPlayer = false;
let lastDamageTime = 0;
gameScene.playerDamage = function(player, enemy) {
//here I set the delay on damage
if (this.time.now > lastDamageTime) {
overlapPlayer = true;
player.lives--;
lastDamageTime = this.time.now + 10;
//here I was just trying to create the appearance and attenuation along the edges around the edges
if (overlapPlayer == true) {
this.tweens.add({
targets: this.damageFrame,
alpha: 1,
ease: 'Linear',
duration: 100,
repeat: 0
});
overlapPlayer = false;
}
}
return this.hideDamageFrame();
}
gameScene.hideDamageFrame = function() {
if (overlapPlayer == false) {
this.tweens.add({
targets: this.damageFrame,
alpha: 0,
ease: 'Linear',
duration: 100,
repeat: 0
});
}
}