1
0
Fork 0

Added some blinking effects to better display value changes

This commit is contained in:
Michaël Lemaire 2017-11-30 01:31:54 +01:00
parent a2ad1ecab0
commit 90ec4491b2
3 changed files with 31 additions and 9 deletions

View file

@ -14,7 +14,7 @@ module TK.SpaceTac.UI {
// Ship sprite
sprite: Phaser.Image
// Statis effect
// Stasis effect
stasis: Phaser.Image
// HSP display
@ -158,16 +158,19 @@ module TK.SpaceTac.UI {
this.toggle_hsp.manipulate("value")(1500);
this.hull_bar.setValue(this.ship.getValue("hull"), this.ship.getAttribute("hull_capacity") || 0);
this.hull_text.text = `${this.ship.getValue("hull")}`;
this.battleview.animations.blink(this.hull_text);
} else if (event.code == "shield") {
this.toggle_hsp.manipulate("value")(1500);
this.shield_bar.setValue(this.ship.getValue("shield"), this.ship.getAttribute("shield_capacity") || 0);
this.shield_text.text = `${this.ship.getValue("shield")}`;
if (this.shield_bar.getValue() == 0) {
this.battleview.animations.blink(this.shield_text);
/*if (this.shield_bar.getValue() == 0) {
this.displayEffect("Shield failure", false);
}
}*/
} else if (event.code == "power") {
this.toggle_hsp.manipulate("value")(1500);
this.power_text.text = `${this.ship.getValue("power")}`;
this.battleview.animations.blink(this.power_text);
}
return 0;
} else if (event instanceof ShipAttributeDiff) {
@ -230,6 +233,9 @@ module TK.SpaceTac.UI {
setPlaying(playing: boolean) {
this.frame.alpha = playing ? 1 : 0.35;
this.frame.visible = this.ship.alive;
/*if (playing) {
this.battleview.animations.blink(this.frame);
}*/
}
/**
@ -237,11 +243,14 @@ module TK.SpaceTac.UI {
*/
setDead(dead = true) {
if (dead) {
this.displayEffect("stasis", false);
//this.displayEffect("stasis", false);
this.stasis.visible = true;
this.stasis.alpha = 0;
this.battleview.animations.blink(this.stasis, 0.9, 0.7);
} else {
this.stasis.visible = false;
}
this.setPlaying(false);
this.battleview.animations.setVisible(this.stasis, dead, 400);
this.alpha = dead ? 0.3 : 1;
}
/**

View file

@ -61,7 +61,7 @@ module TK.SpaceTac.UI {
// Move to a given location on screen
moveTo(x: number, y: number, duration: number) {
if (duration && (this.x != x || this.y != y)) {
this.view.animations.addAnimation(this, {x: x, y: y}, duration, Phaser.Easing.Linear.None);
this.view.animations.addAnimation(this, { x: x, y: y }, duration);
} else {
this.x = x;
this.y = y;

View file

@ -142,9 +142,9 @@ module TK.SpaceTac.UI {
/**
* Add an asynchronous animation to an object.
*/
addAnimation(obj: any, properties: any, duration: number, ease: Function, delay = 0): Promise<void> {
addAnimation(obj: any, properties: any, duration: number, ease: Function = Phaser.Easing.Linear.None, delay = 0): Promise<void> {
return new Promise((resolve, reject) => {
let tween = this.tweens.create(obj);
let tween = this.createTween(obj);
tween.to(properties, duration, ease, false, delay);
tween.onComplete.addOnce(() => {
this.tweens.remove(tween);
@ -154,6 +154,19 @@ module TK.SpaceTac.UI {
});
}
/**
* Catch the player eye with a blink effect
*/
async blink(obj: any, alpha_on = 1, alpha_off = 0.3, times = 3): Promise<void> {
if (obj.alpha != alpha_on) {
await this.addAnimation(obj, { alpha: alpha_on }, 150);
}
for (let i = 0; i < times; i++) {
await this.addAnimation(obj, { alpha: alpha_off }, 150);
await this.addAnimation(obj, { alpha: alpha_on }, 150);
}
}
/**
* Interpolate a rotation value
*