erikwatson / Bramble

A little JS game engine for jamming on prototypes.
MIT License
0 stars 1 forks source link

Input Changed #1

Open erikwatson opened 6 years ago

erikwatson commented 6 years ago

We could do with a nice way to convert the large input objects of Keyboard and Mouse to condensed versions of themselves, where they only contain the differences since the last tick.

I noticed that this might be desirable when trying to implement an online game with Websockets, it would be nice to send only the inputs that have changed to the server rather than the entire input state even when nothing has changed.

Something like this seems alright for now.

import { keyboard, mouse } from 'bramble'

const changedInput = {
  keyboard: keyboard.diff(),
  mouse: mouse.diff()
}
erikwatson commented 6 years ago

It would be useful if we could do a keyboard.diff({ keyState }) to get the difference between this and whatever other key state we have.

If no object is passed in to diff it just uses the previous keystate by default?

erikwatson commented 5 years ago

I did work on this a bit, it worked nicely for the mouse state but the keyboard was more challenging. Will need to rethink my approach.