@flare-engine/输入
指针/触出/手势/虚拟控制/游戏板/键盘输入. InputManager 每帧投票; Pointer 暴露主要触摸(开始当前手势的手指) isDown 编号 : justPressed 编号 : delta ——其他同时触摸只达到 touches[]永远 pointer,当主升起时,它不会转动到剩下的手指上: pointer 在每一次接触开始前保持原地不动,新媒体开始新的初级; GestureDetector 出自自 / swipe / sick / long-press; 仅数据 VirtualJoystick + 键 VirtualButton 状态( RN 组件位于 @flare-engine/react(三); GamepadSource + 键 RemapTable 覆盖游戏板投票和持续重新组合; createKeyboard 提供缓冲 isDown 编号 : wasPressed 编号 : wasReleased 边缘/ 每平方 KeyboardEvent.code 带有模糊清晰的语义.
每个边框的旗帜有两种刻意的形状:每块布林地(Pointer.justPressed/justReleased, (中文(简体) ), VirtualButtonState.justPressed/justReleased, (中文(简体) ), GamepadButtonState.justPressed/justReleased)对于您已经持有引用和按键查询函数的状态(KeyboardState.wasPressed/wasReleased(code), (中文(简体) ), wasButtonPressed/wasButtonReleased(state, button)(a) 以身份证明处理的状态.
安装
bun add @flare-engine/input
使用量
import {
InputManager,
GestureDetector,
createWebGamepadSource,
attachKeyboardListeners,
} from '@flare-engine/input';
const input = new InputManager();
const gestures = new GestureDetector();
gestures.onSwipe.add((e) => console.log(e.direction));
// Web: attach turnkey keyboard listener (mobile/RN: call input.keyboard.keyDown/keyUp directly)
attachKeyboardListeners(input.keyboard, window);
input.pollGamepads(createWebGamepadSource(navigator));
input.update(); // resets all per-frame edge flags including keyboard
平台覆盖
KeyboardState 财务报告和审定财务报表 KeyBindings 是平台中性(移动+网络):
- 网页 —— 说
attachKeyboardListeners(kb, window)是一个提供反馈的统包 DOM 适配器keyDown编号 :keyUp本地事件和电话kb.clear()打开blur(按键后卫. 它故意不打电话preventDefault——光用让 Space/rows 滚动并 Tab 移动 DOM 焦点. 对于游戏模式输入,请附上您自己的收听者preventDefaults 游戏键和前置键kb.keyDown(ev.code)。 。 。 . - 移动/ RN - 打电话
kb.keyDown(code)编号 :kb.keyUp(code)直接取自硬件键盘本地模块或屏幕上源. 同样的边缘语义适用.
// Action binding example (platform-neutral)
import { InputManager, isActionDown, wasActionPressed, type KeyBindings } from '@flare-engine/input';
const bindings: KeyBindings = { jump: ['Space', 'KeyW'], fire: ['KeyZ', 'KeyJ'] };
function update(input: InputManager, player: { jump(): void; fire(): void }) {
// in update loop:
if (wasActionPressed(input.keyboard, bindings, 'jump')) player.jump();
if (isActionDown(input.keyboard, bindings, 'fire')) player.fire();
}
见 API 规格。 。 。 .
许可证
阿帕奇 - 2.0