Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isPressed and control listener #223

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open

Add isPressed and control listener #223

wants to merge 2 commits into from

Conversation

Techassi
Copy link

isPressed function

isPressed is a quality of life adjustment. This function enables to use

f.Keyboard.isPressed(f.KEYBOARD_CODE.A)

to check if one key is pressed. This eliminates the rather clunky use of

f.Keyboard.isPressedOne([f.KEYBOARD_CODE.A])

control listener

The new control listener in FUDGE/Core/Source/Control/Listener.ts enables a more straight forward use of controls.

let listener = new f.Listener('listener', 1, f.KEYBOARD_CODE.A, f.CONTROL_TYPE.PROPORTIONAL, true);

Currently you can (only) pass one keycode to listen for. In the future this can be extended to use an array of f.KEYBOARD_CODE.

listener.setInputMapped(1, 0);

With setInputMapped(_active, _inactive) the listener can automatically map _active and _inactive to key presses of the provided key.

listener.getOutput()

With getOutput() you can retrieve the calculated output as usual (e.g. in the game loop)

This commit adds the keyPressed function to the Keybard class.

keyPressed acts in nearly the same way as keyPressedOne does. The only difference is that this function checks a single key instead of an array of keys.
This commit adds a control listener which uses the internal loop to listen for keyboard inputs.

Using this listener eliminates the use of setInput on every loop frame.
@JirkaDellOro
Copy link
Owner

Vielen Dank für die Beteiligung. isPressed ist unkritisch. Bei dem Listener habe ich Bedenken, da er an die Game-Loop gekoppelt ist. Die läuft aber nicht zwingend, die Controls sollten davon unabhängig sein. Wenn wir das bauen, ist es eher etwas für Aid statt für Core.

@Techassi
Copy link
Author

Techassi commented Nov 20, 2020

Zu isPressed: super!

Zu Listener:

Wenn der Game Loop nicht läuft, wird dann nicht auch die Controls hinfällig? Oder anders formuliert: Wenn der Game Loop nicht läuft werden keine Inputs mit setInput() gesetzt und keine Outputs mit getOutput() errechnet.

Ich hielt es für eine gute Idee einen Listener an den zentralen Game Loop zu koppeln, da dieser bei jedem Frame die nötigen Berechnungen des gesamten Spiels übernimmt. Wie wäre deine Idee, um einen solchen Listener zu realisieren? Welcher Loop sollte hier das "hören" übernehmen?

Ergänzung

Ich habe volkommen vergessen, dass ich eine weitere Funktion mapToValueOne() eingeführt habe. Diese is das Pendant zu isPressed() wie mapToValue() zu isPressedOne(). Hier sollte man vielleicht auch an einen Rename dieser Funktionen denken, um diese etwas aussagekräftiger zu machen und in EInklang zu einander zu bringen:

isPressed -> isPressedOne / isPressed
isPressedOne -> isPressedMulti
isPressedCombo -> isPressedCombo

mapToValueOne -> mapToValue
mapToValue -> mapToValueMulti
@JirkaDellOro
Copy link
Owner

Wann die Inputs der Controls gefüttert werden, ist eine Frage auf einer höheren Ebene. Häufig geschieht das ereignisgesteuert und nicht nach einem Polling durch die Gameloop.

Ich wollte dir vor allem Feedback geben damit Du weißt, dass ich mir das alles erst in Ruhe anschauen werde.

@Techassi
Copy link
Author

Alles klar!

Freue mich auf dein Feedback und die gemeinsame Diskussion zu diesem Thema / PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants