1
0
Fork 0
spacetac/src/ui/common/Animation.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-02-09 00:00:35 +00:00
module TS.SpaceTac.UI {
// Utility functions for animation
export class Animation {
// Display an object, fading in using opacity
2017-01-08 22:42:53 +00:00
static fadeIn(game: Phaser.Game, obj: PIXI.DisplayObject, duration: number = 1000, alpha: number = 1): void {
if (!obj.visible) {
obj.alpha = 0;
obj.visible = true;
}
var tween = game.tweens.create(obj);
2017-01-08 22:42:53 +00:00
tween.to({ alpha: alpha }, duration);
tween.start();
}
// Hide an object, fading out using opacity
static fadeOut(game: Phaser.Game, obj: PIXI.DisplayObject, duration: number = 1000): void {
var tween = game.tweens.create(obj);
2017-01-08 22:42:53 +00:00
tween.to({ alpha: 0 }, duration);
tween.start();
}
// Set visibility of an object, using either fadeIn or fadeOut
static setVisibility(game: Phaser.Game, obj: PIXI.DisplayObject, visible: boolean, duration: number = 1000): void {
if (visible) {
Animation.fadeIn(game, obj, duration);
} else {
Animation.fadeOut(game, obj, duration);
}
}
}
}