1
0
Fork 0

Fixed Repulser making the ships' sprites disappear

This commit is contained in:
Michaël Lemaire 2018-06-13 00:36:08 +02:00
parent 60d3cd2db7
commit 4713c8d09a
3 changed files with 26 additions and 16 deletions

View File

@ -60,16 +60,16 @@ module TK.SpaceTac.UI {
this.frame_owner = builder.image(this.enemy ? "battle-hud-ship-enemy" : "battle-hud-ship-own", 0, 0, true);
this.setPlaying(false);
this.frame_hover = builder.image("battle-hud-ship-hover", 0, 0, true);
this.frame_hover.visible = false;
this.frame_hover.setVisible(false);
// Add ship sprite
this.sprite = builder.image(`ship-${ship.model.code}-sprite`, 0, 0, true);
this.sprite.rotation = ship.arena_angle;
this.sprite.setRotation(ship.arena_angle);
// Add stasis effect
this.stasis = builder.image("battle-hud-ship-stasis", 0, 0, true);
this.stasis.alpha = 0.9;
this.stasis.visible = !ship.alive;
this.stasis.setAlpha(0.9);
this.stasis.setVisible(!ship.alive);
// HSP display
this.hsp = builder.container("hsp", 0, 34);
@ -332,12 +332,14 @@ module TK.SpaceTac.UI {
*/
async moveToArenaLocation(x: number, y: number, facing_angle: number, speed = 1, engine = true): Promise<void> {
if (speed) {
let animation = bound(this.arena.view.animations, engine ? "moveInSpace" : "moveTo");
await animation(this, x, y, facing_angle, this.sprite, speed);
if (engine) {
await this.arena.view.animations.moveInSpace(this, x, y, facing_angle, this.sprite, speed);
} else {
await this.arena.view.animations.moveTo(this, x, y, facing_angle, this.sprite, speed);
}
} else {
this.x = x;
this.y = y;
this.sprite.rotation = facing_angle;
this.setPosition(x, y);
this.sprite.setRotation(facing_angle);
}
}

View File

@ -166,9 +166,14 @@ module TK.SpaceTac.UI {
* Add an asynchronous animation to an object.
*/
addAnimation<T extends object>(obj: T, properties: Partial<T>, duration: number, ease = "Linear", delay = 0, loop = 1, yoyo = false): Promise<void> {
return new Promise(resolve => {
this.killPrevious(obj, keys(properties));
this.killPrevious(obj, keys(properties));
if (!duration) {
copyfields(properties, obj);
return Promise.resolve();
}
return new Promise(resolve => {
this.tweens.add(merge<object>({
targets: obj,
ease: ease,
@ -239,9 +244,12 @@ module TK.SpaceTac.UI {
* Returns the animation duration.
*/
moveTo(obj: Phaser.GameObjects.Components.Transform, x: number, y: number, angle: number, rotated_obj = obj, speed = 1, ease = true): Promise<void> {
let duration_rot = this.rotationTween(rotated_obj, angle, 0.5 * speed);
let duration_pos = arenaDistance(obj, { x: x, y: y }) * 2;
return this.addAnimation(obj, { x: x, y: y }, duration_pos / speed, ease ? "Quad.easeInOut" : "Linear");
let duration = arenaDistance(obj, { x: x, y: y }) * 2 / speed;
return Promise.all([
this.rotationTween(rotated_obj, angle, speed * 0.5, ease ? "Cubic.easeInOut" : "Linear"),
this.addAnimation(obj, { x: x, y: y }, duration, ease ? "Quad.easeInOut" : "Linear"),
]).then(nop);
}
/**
@ -253,7 +261,8 @@ module TK.SpaceTac.UI {
this.killPrevious(obj, ["x", "y"]);
if (x == obj.x && y == obj.y) {
return this.rotationTween(rotated_obj, angle, 0.5 * speed);
let distance = Math.abs(angularDifference(rotated_obj.rotation, angle));
return this.rotationTween(rotated_obj, angle, distance * 500 / speed);
} else {
this.killPrevious(rotated_obj, ["rotation"]);
let distance = Target.newFromLocation(obj.x, obj.y).getDistanceTo(Target.newFromLocation(x, y));

View File

@ -91,7 +91,6 @@ module TK.SpaceTac.UI {
let distance = Math.sqrt(dx * dx + dy * dy);
let angle = Math.atan2(-dy, dx);
this.setMoving(true);
console.error(fleet_location, location, angle);
this.goToOrbitPoint(angle, 40, 1, true).then(() => {
this.setRotation(-angle);
let duration = 10000 * distance / speed;