BeeInput — Documentazione Tecnica
Tastiera, mouse e touch:
isPressed,
wasPressed
📁 Panoramica
BeeInput legge tastiera, mouse e
dita. Vive in
src/input/BeeInput.js.
Il motore la costruisce sul canvas
(gioco.input) e a fine frame
chiama endFrame(), anche in
pausa.
I tasti stanno su due strati.
La tastiera tiene il code
(KeyA, Space,
ArrowLeft, ShiftLeft)
e il carattere di quel
keydown (a,
Shift).
setKey tiene i tasti virtuali,
quelli di joystick e pulsanti touch.
isPressed è true se almeno uno
dei due strati è giù.
wasPressed è true solo nel frame
in cui quel nome passa da spento a premuto.
endFrame spegne l’edge.
Il tasto tenuto resta in
isPressed.
📁 Frame
L’edge si legge
durante update e draw. Poi
endFrame lo azzera.
-
pressione
Il nome passa a giù:
wasPressedeisPressedtrue. Ilkeyupusa il carattere delkeydown. -
endFrame
wasPressedtorna false.isPressedresta true finché il tasto è tenuto. Vale anche permouse.wasPressed. -
rilascio
keyupoblurspengono la tastiera.setKeynon si spegne con loro.
📁 Dove è facile sbagliare
Il carattere è quello del keydown.
KeyA con a, poi
keyup con A perché
è arrivato lo Shift: si spengono sia
a sia KeyA.
isPressed('ShiftLeft') è il code.
isPressed('Shift') è il carattere
di quel keydown, e resta true
se è ancora giù
ShiftLeft o
ShiftRight.
Pausa.
In pausa scene ed entità non fanno update.
Il callback update e
BeeUI sì. Poi
endFrame consuma l’edge.
Un tap solo in quel frame non arriva alle
entità dopo. Un tasto ancora tenuto si
rilegge con isPressed.
Mouse e dita.
mousedown è sul canvas, qualunque
bottone, e accende
pressed e
wasPressed.
mousemove e
mouseup sono sulla window:
il punto può essere negativo o oltre il
canvas, e il rilascio fuori spegne
pressed.
Un mouse con
firesTouchEvents si ignora.
L’ultimo dito spegne
pressed e prende la posizione
da changedTouches.
📁 Riepilogo API
keys viene riallineato a
isPressed. Lo stato si legge
da isPressed e
wasPressed.
Senza canvas il costruttore lancia
BeeInput: canvas required.
| Membro | Ritorna | Scopo |
|---|---|---|
new BeeInput(canvas) |
BeeInput |
Listener su window e canvas.
Mouse a 0, 0,
niente tasti, niente tocchi. |
isPressed(name) |
boolean |
True se il code, il carattere
ricordato o
setKey tengono
name.
|
wasPressed(name) |
boolean |
True solo nel frame in cui
name è passato a
giù. endFrame lo
spegne.
|
setKey(name, down) |
Strato virtuale.
down true lo accende,
false lo spegne.
Non toglie la tastiera, e la
tastiera non toglie lui.
Se prima era spento, segna
l’edge.
|
|
endFrame() |
Svuota gli edge dei tasti e
mouse.wasPressed.
Non rilascia i tasti tenuti né
mouse.pressed.
Lo chiama il loop.
|
|
getCanvasPosition(clientX, clientY) |
{ x, y } |
Pixel del bitmap:
(client - rect) * (canvas / rect).
Rettangolo 0×0 o
scala non finita:
{ x: 0, y: 0 }.
|
mouse |
x, y,
pressed,
wasPressed.
Il primo dito copia
x e y
sul mouse.
|
|
touches |
{ id, x, y }[] |
Dita attive, in pixel canvas.
id è
identifier.
Lista vuota quando non c’è
nessun dito.
|
destroy() |
Toglie i listener.
BeeEngine.destroy
lo chiama. Dopo, un
keydown non cambia
isPressed.
|
