@tastic/core
v0.2.0
Published
Required foundation for @tastic/* game packages: Vec2 and vector math, clamp, a dt-clamped RAF game-loop hook, and environment-capability detection (touch-primary vs. keyboard-likely)
Maintainers
Readme
@tastic/core
Required foundation for @tastic/* game packages. Every other @tastic/* package (present and
future — @tastic/physics, @tastic/input, and so on) can assume this is available and depends on
it directly, so anything genuinely domain-agnostic lives here rather than being duplicated in
whichever package happens to need it first.
What it does
Vec2— a{x, y}type plusadd/subtract/scale/length/distance/dot/normalize. Used by collision/force math, drag/aim-vector tracking, and board/layout geometry alike, so it doesn't belong to any one of those.clamp(value, min, max)— keep a number within a range.computeClampedDt(timestamp, lastTimestamp, maxDt)— turns the raw gap between tworequestAnimationFrametimestamps into a frame-rate-independent, clampeddtmultiplier, so a single simulation/tick step never represents more time thanmaxDtnominal frames even after a stutter or a background/foreground cycle.useGameLoop(onTick, { enabled, maxDt })— drivesonTick(dt)once per frame viarequestAnimationFramefor as long asenabledis true, usingcomputeClampedDtinternally. Game-specific gating (pause state, game phase) stays out of the hook — compute your ownenabledboolean and pass it in.useIsTouchPrimaryDevice()— best-effort environment-capability detection: is this player likely on touch (native, or a touch-primary web viewport) vs. likely to have a keyboard/mouse (a wide-viewport web browser with a fine pointer)? Useful for deciding whether to offer a keyboard-scheme picker or lean on touch/swipe controls. Alwaystrueon native.
Usage
import { clamp, computeClampedDt, distance, useGameLoop, useIsTouchPrimaryDevice, type Vec2 } from '@tastic/core'
function useMyGameLoop(step: (dt: number) => void, enabled: boolean) {
useGameLoop(step, { enabled, maxDt: 2.5 })
}Install (local dev via yalc)
Not published to the public npm registry yet.
cd react-native-game-core
npm run build
yalc publish
cd ../your-game
yalc add @tastic/core
npm installRe-run npm run build && yalc push from this package after any change to propagate it to every
linked consumer at once.
Peer dependencies
react (>=19.0.0) — required for the whole package. Vec2/clamp/computeClampedDt are
plain, dependency-free TypeScript in source, but the package ships as one bundle alongside
useGameLoop/useIsTouchPrimaryDevice, so react is needed to load any of it. This is a React
Native toolkit either way, so every real consumer already has react installed regardless.
