Controllers: Difference between revisions

From Pico-8 Wiki
Jump to navigation Jump to search
imported>Dddaaannn
(Created page with "Pico-8 supports the use of game controllers that can be connected to a computer, either with a wired USB connection or a wireless Bluetooth connection. Pico-8's controller sup...")
 
imported>Dddaaannn
No edit summary
Line 8: Line 8:


For a complete list of default key mappings for players 1 and 2, see [[Btn|btn()]].
For a complete list of default key mappings for players 1 and 2, see [[Btn|btn()]].
You can customize the key mappings for players 1 and 2 interactively using the [[Keyconfig|keyconfig]] command. You can also edit [[Configuration|config.txt]] directly.


== Configuring controllers ==
== Configuring controllers ==

Revision as of 08:49, 26 January 2017

Pico-8 supports the use of game controllers that can be connected to a computer, either with a wired USB connection or a wireless Bluetooth connection. Pico-8's controller support is based on the SDL library.

A game can have up to 8 simultaneous players. Players 1 and 2 can use game controllers or corresponding keys on the keyboard. Players 3-8 must use game controllers.

Keyboard controls

While a game is playing, Pico-8 recognizes keyboard presses as controls for players 1 and 2. For example, player 1 can use the cursor keys, Z, and X for the six possible inputs.

For a complete list of default key mappings for players 1 and 2, see btn().

You can customize the key mappings for players 1 and 2 interactively using the keyconfig command. You can also edit config.txt directly.

Configuring controllers

You can configure controller mappings by editing the sdl_controllers.txt file in the Pico-8 configuration directory. Each line of the file is a controller mapping in the format used by SDL. Here is an example of a mapping line:

79000000000000001100000000000000,Retrolink Classic Controller,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a3,lefty:a4,platform:Mac OS X,

You can generate this line using one of these tools:

The complete procedure for using GamePadTool:

  1. Connect one or more controllers to your computer.
  2. Start GamePadTool. The tool should detect the controllers and allow you to select between them.
  3. Select a controller, then click "Copy Mapping String." This copies the mapping string to your clipboard.
  4. Edit the sdl_controllers.txt file in the Pico-8 configuration directory. Paste the mapping string onto its own line, then save the file.
  5. Start (or restart) Pico-8 to use the new configuration.

(TODO: More information about setting up multiple controllers, and associating controllers with players.)

Testing controllers

Here is code for a simple cart that lets you test controllers for all players:

function _update()
end
function _draw()
 cls()
 for p=0,8 do
   print(''..p..':', 0, p*7, 1)
   for b=0,6 do
     if btn(b,p) then
       print(b, b*5 + 10, p*7, p+1)
     end
   end
 end
end

See also