Active: {joystickActive ? "Yes" : "No"}
X: {joystickX.toFixed(2)}
Y: {joystickY.toFixed(2)}
);
}
// Programmatically control joystick (for AI or automation)
function AIController() {
const { setJoystick, resetJoystick } = useJoystickStore();
useEffect(() => {
// Simulate joystick input
const interval = setInterval(() => {
const angle = Date.now() / 1000;
setJoystick(Math.cos(angle), Math.sin(angle));
}, 16);
return () => {
clearInterval(interval);
resetJoystick();
};
}, []);
return null;
}
```
--------------------------------
### Use Button Store for Button State Management (React/TypeScript)
Source: https://context7.com/pmndrs/bvhecctrl/llms.txt
This snippet illustrates using the useButtonStore to manage virtual button states, supporting custom button IDs. It shows how to read button states reactively, programmatically control button activity (e.g., simulating a jump), and includes an example of defining custom buttons in the UI. Dependencies include bvhecctrl.
```tsx
import { useButtonStore, VirtualButton } from "bvhecctrl";
import { useEffect } from "react";
function CustomButtonLogic() {
// Read button states reactively
const buttons = useButtonStore((state) => state.buttons);
useEffect(() => {
if (buttons.dance) {
console.log("Dance button is pressed!");
}
if (buttons.interact) {
console.log("Interact button is pressed!");
}
}, [buttons]);
return null;
}
// Programmatically control buttons
function AutomatedInput() {
const { setButtonActive, resetAllButtons } = useButtonStore();
const simulateJump = () => {
setButtonActive("jump", true);
setTimeout(() => setButtonActive("jump", false), 100);
};
const simulateRunning = (running: boolean) => {
setButtonActive("run", running);
};
useEffect(() => {
// Clean up on unmount
return () => resetAllButtons();
}, []);
return (