Skip to content

Commit 7599926

Browse files
committed
Add a fade animation to the gate piece
1 parent 4626c8a commit 7599926

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/nodes/GatePiece.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getBlochCoords, octet, rotationGate, type Axis } from "../quantum";
66
import GameNode from "./GameNode";
77

88
const rotationSpeed = Math.PI / 16;
9+
const opacitySpeed = 1;
910

1011
// A piece representing a (1-qubit) gate
1112
export default class GatePiece extends GameNode {
@@ -17,6 +18,9 @@ export default class GatePiece extends GameNode {
1718
angleMarker: Graphics;
1819
outline: Graphics;
1920

21+
fadingOut = false;
22+
doFade = false;
23+
2024
constructor(axis: Axis, angle: number) {
2125
super();
2226
this.axis = axis;
@@ -70,6 +74,20 @@ export default class GatePiece extends GameNode {
7074

7175
tick(time: Ticker) {
7276
this.background.rotation += (time.deltaMS * rotationSpeed) / 1000;
77+
if (!this.doFade) {
78+
this.outline.alpha = 0;
79+
} else {
80+
this.outline.alpha +=
81+
((time.deltaMS * opacitySpeed) / 1000) * (this.fadingOut ? -1 : 1);
82+
if (this.outline.alpha >= 1) {
83+
this.outline.alpha = 1;
84+
this.fadingOut = true;
85+
}
86+
if (this.outline.alpha <= 0) {
87+
this.outline.alpha = 0;
88+
this.fadingOut = false;
89+
}
90+
}
7391
}
7492

7593
rotate() {

src/nodes/Player.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export default class Player extends GameNode {
255255
this.pieceCount++;
256256
}
257257
if (this.board.current instanceof GatePiece) {
258-
this.board.current.outline.alpha = 1;
258+
this.board.current.doFade = true;
259259
}
260260
// Increase level
261261
const levelCount =

0 commit comments

Comments
 (0)