1
0
Fork 0

Added Animation helper to handle fadein and fadeout

This commit is contained in:
Michaël Lemaire 2015-02-20 01:00:00 +01:00
parent e01cf6bb12
commit d56c19be1e
7 changed files with 45 additions and 16 deletions

View file

@ -105,11 +105,7 @@ module SpaceTac.View {
// Update the active status, from the action canBeUsed result
updateActiveStatus(): void {
var active = this.action.canBeUsed(this.battleview.battle, this.ship);
var tween = this.game.tweens.create(this.layer_active);
tween.to({alpha: active ? 1 : 0});
tween.start();
Animation.setVisibility(this.game, this.layer_active, active, 500);
this.input.useHandCursor = active;
}
}

View file

@ -60,13 +60,13 @@ module SpaceTac.View {
// Set the hovered state on this ship
// This will toggle the hover effect
setHovered(hovered: boolean) {
this.hover.visible = hovered;
Animation.setVisibility(this.game, this.hover, hovered, 200);
}
// Set the playing state on this ship
// This will toggle the "playing" indicator
setPlaying(playing: boolean) {
this.playing.visible = playing;
Animation.setVisibility(this.game, this.playing, playing, 500);
}
// Move the sprite to a location

View file

@ -190,7 +190,7 @@ module SpaceTac.View {
this.exitTargettingMode();
this.interacting = enabled;
this.icon_waiting.visible = !this.interacting;
Animation.setVisibility(this.game, this.icon_waiting, !this.interacting, 100);
}
// Enter targetting mode

View file

@ -51,6 +51,9 @@ module SpaceTac.View {
case "fire":
this.processFireEvent(<Game.FireEvent>event);
break;
case "endbattle":
this.view.setInteractionEnabled(false);
break;
}
}

View file

@ -19,7 +19,7 @@ module SpaceTac.View {
// Set the currently displayed ship (null to hide)
setShip(ship: Game.Ship) {
this.ship = ship;
this.visible = (ship !== null);
Animation.setVisibility(this.game, this, ship !== null, 200);
}
}
}

View file

@ -79,17 +79,13 @@ module SpaceTac.View {
// Set the playing status
setPlaying(playing: boolean) {
var tween1 = this.game.tweens.create(this.layer_playing);
tween1.to({alpha: playing ? 1 : 0});
tween1.start();
var tween2 = this.game.tweens.create(this.layer_normal);
tween2.to({alpha: playing ? 0 : 1});
tween2.start();
Animation.setVisibility(this.game, this.layer_playing, playing, 500);
Animation.setVisibility(this.game, this.layer_normal, !playing, 500);
}
// Set the hovered status
setHovered(hovered: boolean) {
this.layer_hover.visible = hovered;
Animation.setVisibility(this.game, this.layer_hover, hovered, 200);
}
}
}

View file

@ -0,0 +1,34 @@
module SpaceTac.View {
"use strict";
// Utility functions for animation
export class Animation {
// Display an object, fading in using opacity
static fadeIn(game: Phaser.Game, obj: PIXI.DisplayObject, duration: number = 1000): void {
if (!obj.visible) {
obj.alpha = 0;
obj.visible = true;
}
var tween = game.tweens.create(obj);
tween.to({alpha: 1}, 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);
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);
}
}
}
}