Added Animation helper to handle fadein and fadeout
This commit is contained in:
parent
e01cf6bb12
commit
d56c19be1e
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -51,6 +51,9 @@ module SpaceTac.View {
|
|||
case "fire":
|
||||
this.processFireEvent(<Game.FireEvent>event);
|
||||
break;
|
||||
case "endbattle":
|
||||
this.view.setInteractionEnabled(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
34
src/scripts/view/common/Animation.ts
Normal file
34
src/scripts/view/common/Animation.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue