bberak / react-game-engine

A lightweight Game Engine for the web (React) 🕹⚡🎮
MIT License
420 stars 25 forks source link

Better onKeyPress #15

Closed nhmbounteous closed 4 years ago

nhmbounteous commented 4 years ago

There is a lag with the onKeyPress events in browsers. I would suggest creating a object that contains valid input keys. onKeyDown load that key into the object as true and onKeyUp set the key to false.

bberak commented 4 years ago

Hi @nhmbounteous,

The game engine provides provides both onKeyDown and onKeyUp events. Here is a list of all the provided events:

onClick onContextMenu onDoubleClick onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onWheel onTouchCancel onTouchEnd onTouchMove onTouchStart onKeyDown onKeyPress onKeyUp

Using these basic events, you can create a variety of controllers similar to what you descibed. Here is a basic keyboard controller that is wrapped into a system.

Let me know if that helps!

nhmbounteous commented 4 years ago

@bberak I was suggesting on implementing a similar controller utility. I think I understand the point of using the default events. However, do you think it would be worth developing utility systems?

bberak commented 4 years ago

@nhmbounteous I wouldn't be inclined to make them part of the core project because in my experience every game/app will have slightly different needs.

However, I would totally understand if someone created and distributed a library of common systems that can be plugged into react-game-engine. That is kind of where I was going with the react-game-engine-template project. The template repo contains a bunch of utilities and systems I use over and over in my personal projects (but they might not be suitable for everyone).

nhmbounteous commented 4 years ago

Sounds good, thank you for the responsiveness :D

bberak commented 4 years ago

No problems @nhmbounteous, more than happy to chat about this stuff!