Skip to content

Hooks

React hooks provided by Strata packages.

Blend multiple animations with weighted mixing.

import { useAnimationBlend } from '@strata-game-library/core';
function Character() {
const { blend, setWeight } = useAnimationBlend({
idle: idleAnimation,
walk: walkAnimation,
run: runAnimation,
});
useEffect(() => {
setWeight('walk', velocity / maxSpeed);
}, [velocity]);
return <Character animation={blend} />;
}
PropertyTypeDescription
blendAnimationBlended animation
setWeight(name: string, weight: number) => voidSet animation weight
getWeight(name: string) => numberGet current weight

Handle touch/mouse interaction with fur.

import { useFurInteraction } from '@strata-game-library/core';
function InteractiveFur() {
const { onPointerMove, deformation } = useFurInteraction();
return (
<FurMesh
onPointerMove={onPointerMove}
deformation={deformation}
/>
);
}
PropertyTypeDescription
onPointerMove(event: PointerEvent) => voidEvent handler
deformationDeformationMapCurrent deformation state
reset() => voidReset deformation

Get device information (React Native / Capacitor).

import { useDevice } from '@strata-game-library/capacitor-plugin/react';
function Game() {
const device = useDevice();
return (
<div style={{ paddingTop: device.safeAreaInsets.top }}>
<p>Platform: {device.platform}</p>
<p>Type: {device.deviceType}</p>
<p>Input: {device.inputMode}</p>
</div>
);
}
PropertyTypeDescription
platformstring’ios’, ‘android’, ‘web’, etc.
deviceTypestring’mobile’, ‘tablet’, ‘desktop’
inputModestring’touch’, ‘keyboard’, ‘gamepad’
orientationstring’portrait’, ‘landscape’
safeAreaInsetsobjectSafe area for notches

Get unified input state (React Native / Capacitor).

import { useInput } from '@strata-game-library/capacitor-plugin/react';
function Game() {
const { leftStick, rightStick, buttons, isPressed } = useInput();
useFrame(() => {
player.move(leftStick.x, leftStick.y);
});
if (isPressed('jump')) {
player.jump();
}
return <Player />;
}
PropertyTypeDescription
leftStick{ x: number, y: number }Left joystick (-1 to 1)
rightStick{ x: number, y: number }Right joystick
buttonsRecord<string, boolean>Button states
triggers{ left: number, right: number }Trigger values
isPressed(button: string) => booleanCheck button

Trigger haptic feedback (React Native / Capacitor).

import { useHaptics } from '@strata-game-library/capacitor-plugin/react';
function Game() {
const { light, medium, heavy, custom, isSupported } = useHaptics();
const handleHit = () => {
if (isSupported) medium();
};
return <GameScene onHit={handleHit} />;
}
PropertyTypeDescription
light() => Promise<void>Light haptic
medium() => Promise<void>Medium haptic
heavy() => Promise<void>Heavy haptic
custom(options: HapticsOptions) => Promise<void>Custom haptic
isSupportedbooleanDevice supports haptics

Get localized control hints based on input mode.

import { useControlHints } from '@strata-game-library/capacitor-plugin/react';
function HelpOverlay() {
const hints = useControlHints();
return (
<div>
<p>Move: {hints.movement}</p>
<p>Look: {hints.camera}</p>
<p>Action: {hints.action}</p>
</div>
);
}
PropertyTypeDescription
movementstringMovement hint text
camerastringCamera hint text
actionstringPrimary action hint

All-in-one hook for Capacitor plugin.

import { useStrata } from '@strata-game-library/capacitor-plugin/react';
function Game() {
const {
deviceInfo,
safeArea,
inputMode,
orientation,
triggerHaptics,
} = useStrata();
return <GameScene />;
}