feat: Add toggle for animation to FPV
This commit is contained in:
parent
65eec5f6bd
commit
cc391bc7e4
2 changed files with 32 additions and 4 deletions
|
|
@ -27,18 +27,27 @@ class HippieCrosshair {
|
|||
this.mouseX = canvas.width / 2;
|
||||
this.mouseY = canvas.height / 2;
|
||||
|
||||
// Animation control
|
||||
this.isAnimating = true;
|
||||
this.animationFrameId = null;
|
||||
|
||||
this.setupEventListeners();
|
||||
this.animate();
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
document.addEventListener('mousemove', (e) => {
|
||||
this.mouseX = e.clientX;
|
||||
this.mouseY = e.clientY;
|
||||
document.addEventListener('mousemove', (event) => {
|
||||
this.mouseX = event.clientX;
|
||||
this.mouseY = event.clientY;
|
||||
});
|
||||
}
|
||||
|
||||
animate() {
|
||||
if (!this.isAnimating) {
|
||||
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
||||
return;
|
||||
}
|
||||
|
||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
if (this.showConnector) {
|
||||
|
|
@ -49,7 +58,7 @@ class HippieCrosshair {
|
|||
// TODO: Autom. Zug zum Zentrum hin ermöglichen
|
||||
this.drawCrosshair();
|
||||
|
||||
requestAnimationFrame(() => this.animate());
|
||||
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
||||
}
|
||||
|
||||
drawLine() {
|
||||
|
|
@ -227,4 +236,16 @@ class HippieCrosshair {
|
|||
setLineVisible(visible) {
|
||||
this.showConnector = visible;
|
||||
}
|
||||
|
||||
startAnimation() {
|
||||
this.isAnimating = true;
|
||||
}
|
||||
|
||||
stopAnimation() {
|
||||
this.isAnimating = false;
|
||||
}
|
||||
|
||||
toggleAnimation() {
|
||||
this.isAnimating = !this.isAnimating;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue