Search code examples
javalibgdxpollingeventhandler

LibGDX InputProcessor Documentation


As the documentation on this link suggests

Instead of polling for events, one can process all input events with an InputProcessor.

though then the documentation of InputProcessor says

It will be called each frame before the call to ApplicationListener.render().

As far as I know EventHandlers are called only when the event is fired, thus they are more efficient than polling. Why does it say that it is called each frame ?


Solution

  • From looking at the source code, I can see that the input processor is called in the game loop right before render(), but only with queued up input events that are aquired from event listeners. So behind the scenes, event listeners queue up all input events. Right before render() any queued events are flushed to your game's InputProcessor. If there are none, it won't get any calls.

    I think your quote from the documentation is just trying to tell you at what point in the game lifecycle the input events come through to the processor.