Skip to content

Commit 04d5382

Browse files
committed
chore: add juice utils to base project
Signed-off-by: Scott Westover <scottwestover2006@gmail.com>
1 parent ef0b5db commit 04d5382

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/common/juice-utils.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as Phaser from 'phaser';
2+
3+
/**
4+
* Creates a flash animation effect by using the built in Phaser 3 Timer Events. The provided game object
5+
* will be the target of the effect that is created.
6+
* @param {Phaser.GameObjects.Image | Phaser.GameObjects.Sprite} target The target game object that the effect will be applied to.
7+
* @param {() => void} [callback] The callback that will be invoked when the tween is finished
8+
* @returns {void}
9+
*/
10+
export function flash(target: Phaser.GameObjects.Image | Phaser.GameObjects.Sprite, callback?: () => void): void {
11+
const timeEvent = target.scene.time.addEvent({
12+
delay: 250,
13+
callback: () => {
14+
target.setTintFill(0xffffff);
15+
target.setAlpha(0.7);
16+
17+
target.scene.time.addEvent({
18+
delay: 150,
19+
callback: () => {
20+
target.setTint(0xffffff);
21+
target.setAlpha(1);
22+
if (timeEvent.getOverallProgress() === 1 && callback) {
23+
callback();
24+
}
25+
},
26+
});
27+
},
28+
startAt: 150,
29+
repeat: 3,
30+
});
31+
}

0 commit comments

Comments
 (0)