feat: Add toggle for animation to FPV

This commit is contained in:
sthag 2026-03-22 22:21:26 +01:00
parent 65eec5f6bd
commit cc391bc7e4
2 changed files with 32 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -15,6 +15,9 @@ tags:
<canvas id="view"></canvas>
<header class="io controls">
<nav>
<button onclick="toggleAnimation()">Toggle</button>
</nav>
<nav>
<span>Color</span>
<button onclick="changeColor('black')">Black</button>
@ -70,6 +73,10 @@ tags:
crosshair.setLineVisible(!crosshair.showConnector);
}
function toggleAnimation() {
crosshair.toggleAnimation();
}
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;