TalkIcon animation

This commit is contained in:
Hanusiak Piotr
2022-02-03 16:00:29 +01:00
parent a4cd626c41
commit d087bc02e9
3 changed files with 65 additions and 12 deletions
+57
View File
@@ -0,0 +1,57 @@
import { Easing } from '../../types';
export class TalkIcon extends Phaser.GameObjects.Image {
private shown: boolean;
private showAnimationTween?: Phaser.Tweens.Tween;
private defaultPosition: { x: number, y: number };
private defaultScale: number;
constructor(scene: Phaser.Scene, x: number, y: number) {
super(scene, x, y, 'iconTalk');
this.defaultPosition = { x, y };
this.defaultScale = 0.15;
this.shown = false;
this.setAlpha(0);
this.setScale(this.defaultScale);
this.scene.add.existing(this);
}
public show(show: boolean = true): void {
if (this.shown === show) {
return;
}
this.showAnimation(show);
}
private showAnimation(show: boolean = true) {
if (this.showAnimationTween?.isPlaying()) {
return;
}
this.shown = show;
if (show) {
this.y += 50;
this.scale = 0.05;
this.alpha = 0;
}
this.showAnimationTween = this.scene.tweens.add({
targets: [ this ],
duration: 350,
alpha: show ? 1 : 0,
y: this.defaultPosition.y,
scale: this.defaultScale,
ease: Easing.BackEaseOut,
onComplete: () => {
this.showAnimationTween = undefined;
}
});
}
public isShown(): boolean {
return this.shown;
}
}