Warning: sprintf(): Too few arguments in /home/customer/www/adfxz.com/public_html/wp-content/themes/minimal-grid/assets/lib/breadcrumbs/breadcrumbs.php on line 259

How to do local multiplayer event handling​

These instructions are general and abstract so that it can be applied to lower-level video game libraries such as SDL, SDL2 and SFML.The instructions generally can be applied to any video game library that polls for events similar to SDL, SDL2 and SFML.

Step 1:

Poll for events and save each event into a queue for processing. For multiple players, have a queue for each player and save specific events .

It is recommended to use a specific enum as a data type to save the event info into a queue.

Specifically use queue container since ideally the earliest events need to be processed and removed first which queue allows with its FIFO(First In First Out) nature.


//If button on first joystick is pressed

//save button press to player 1 event queue

if(event == joystick1_button_down){



//If button on second joystick is pressed

//save button press to player 2 event queue

if(event == joystick2_button_down){



Step 2:

Read each event from the queues of each player and do something with it. Read through the queue by reading the event on top of the queue, do an action based on the event, pop the event on top of the queue. Repeat until queue is empty. Repeat for each player.


//while the player 1 event queue is not empty

while(event_queue_player1.empty() == false){

     if(event_queue_player1.front() == JOYSTICK_BUTTON_DOWN){

         //Do something here




//while the player 2 event queue is not empty

while(event_queue_player2.empty() == false){

     if(event_queue_player2.front() == JOYSTICK_BUTTON_DOWN){

         //Do something here