Jump to content

Keyboard input - PixiJS


neulowii
 Share

Recommended Posts

Hello, I am trying to implement keyboard inputs in pixi. Unfortunately pixi does not support this function. They are a lot of good examples which I found but none of them really worked perfect.

I would like to have some kind of events happening when a key is pressed and the PIXI.Container is focused. (like its working with mouse)

Example how I want it to work:

1. main PIXI.Container (stage) have the possibility to move a character with WASD-keys(easy to do)

2. textinput (chat) which is a child of the stage, writing text without perform the events on the parent when pressing WASD

It would be possible to disable all keys on textinput and enable them again on mouse click on the parent again. But it would be a little bit hacky.

Is there a better way which exist or how are you doing this?

Link to comment
Share on other sites

I think it is wised decision that pixijs team exclude keyboard event.
because pixijs is a "render" library not "game" engine.

The easiest way is listening the keyboard event fire from "window" or "document".
Please see [KeyBoard Event](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent).

If you keep going you will start deal with the issued like:
[Sync keyboard event to requestAnimationFrame] (https://gist.github.com/KayacChang/861f6be2970f47eaccc6b0814a930ccf).

The second requirement is about the three topic:
1. how to deal with focus, like "focus event"
2. how to manage the "state" in the application, like "store the current focus target"
3. change the application behavior by the state change, like "observer pattern"
 

Link to comment
Share on other sites

Thanks, I was just thinking if they would exist a general solution. Since I am just using only a chat and the game world itself I am using the pointerover to change the focus.

Is there a possibility to not fire events to the parent and so on if both the child and parent is interactive with the same events?

Edited by neulowii
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...