Autor Tema: [Anarkade Framework] Input Library  (Leído 261 veces)

JaViS

  • Global Moderator
  • *****
  • Mensajes: 1281
  • Karma: 27
    • Anarkade
[Anarkade Framework] Input Library
« en: Agosto 06, 2018, 05:11:52 pm »

Time to share another library from our framework, and I am particularly proud of this one, because I've spent a good time developing it, and I think it can be very useful for other developers.


This library offer many functionalities, but the main one is to provide a unique interface to access different input methods, like the keyboard, a gamepad button, hats or pads, in the same way, with only one function.


The library works by declaring input actions and assigning input methods to these actions.
You can implement multiple input methods to the same action. This way you can, for instance, pause the game pressing start on the gamepad, or ESC in the keyboard.


Código: [Seleccionar]

const
INPUT_CANCEL = 1;
end


...

// assign a key for the input action
input_map_keyboard(INPUT_CANCEL,0, _esc);
// assign a joy button (4) for the same action
input_map_joystick(INPUT_CANCEL, 1, 0, 4);


loop   
   if(input(0,INPUT_UI_CANCEL))
      break;
   end
   frame;
end




This method is very handy for making multi-platform games, by detecting configuring the input based on the platform.


Código: [Seleccionar]

if(os_id==1003)
   // config android back button
   input_map_keyboard(INPUT_PAUSE, 1, 102);
   input_map_keyboard(INPUT_MENU, 1, 102);
end


It also provides a way for the users to configure buttons during the game, and save the configurations on a file for loading them the next time the game starts.


Código: [Seleccionar]
input_load_config("controls.sav");

loop
   if(input(0,INPUT_UI_OK))
      say ("Press any button to assign..." );
      if (!input_listen_assign(1, INPUT_UP))
         say ("Buttons cleared");
      end
   end
   frame;
end
input_save_config("controls.sav");


Lastly, you can also dispatch input actions programmatically. This allows the developers to implement IA players, on-screen controls,  or even netplay the same way emulators do, by sending input information over internet instead of player information.


Código: [Seleccionar]
input_press(1, INPUT_SHOOT);
if(input(1,INPUT_SHOOT))
   //shoot!
end

Take a look at the example at: https://bitbucket.org/pixelatom/bennu_framework/src/master/test_controls/controls_test.prg

And read the library to know all the functions available at https://bitbucket.org/pixelatom/bennu_framework/src/master/library/controls.inc
« última modificación: Noviembre 26, 2018, 03:51:08 pm por JaViS »
Working on Anarkade. A couch multiplayer 2D shooter.

gecko

  • Hero Member
  • *****
  • Mensajes: 807
  • Karma: 47
    • Torres Baldi Studio
Re:[Anarkade Framework] Input Library
« Respuesta #1 en: Agosto 06, 2018, 07:55:40 pm »
This is gold. Thanks a lot for sharing.
Torres Baldi Studio
http://torresbaldi.com