File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments