feat(game) : added ui base for steering

This commit is contained in:
Alex committed 2024-01-22 18:39:20 +01:00
1 parent 4f3e52b9d7
commit 602536bc23
6 files changed
+56 -2

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import React, { useEffect, useRef } from "react";
export const HUD = () => {
const wheel = useRef();
useEffect(() => {
const handleMouseMove = (e) => {
if (wheel.current) {
const { clientX, clientY } = e;
const screenWidth = window.innerWidth;
const rotation = ((clientX - screenWidth / 2) / screenWidth) * 180;
wheel.current.style.left = `${clientX - 100}px`;
wheel.current.style.top = `${clientY - 100}px`;
wheel.current.style.transform = `rotate(${rotation}deg)`;
}
};
window.addEventListener("mousemove", handleMouseMove);
return () => {
window.removeEventListener("mousemove", handleMouseMove);
};
}, []);
return (
<img
ref={wheel}
src="./steering_wheel.png"
alt="steering wheel"
className="steering-wheel"
style={{ position: 'absolute', pointerEvents: 'none', transformOrigin: 'center' }}
/>
);
};