forked from Lunakepio/Mario-Kart-3.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(game) : added ui base for steering
- Loading branch information
Alex
committed
Jan 22, 2024
1 parent
4f3e52b
commit 602536b
Showing
6 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' }} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters