Common Organization of Controls Kit Manual

Basic use

The library designed to be reasonably easy to use while maintain great flexibility and features.

Preparations

First thing you need to do is, obviously, require the library. Then, you create a new control object. You can optionally fill it with data at instant, or may do it later. Then you optionally load saved settings, by pushing your device-key pairs to the object, and also pushing joystick and mouse related data. After that (but not before!) you can reload joystick, that essentially will search for previously used joystick and set it up, the function will return true on success. If you don't have controls to load, you assign default controls, joystick modes and mouse values.

Controls data format

cock.new and cock.setControls are accepting data in specific format that needs to be maintained. It is defined as following:

{ 
  up = { default1 = { "up", "keyboard" }, default2 = { "-y", "mouse axis" },
  down = { default1 = { "down", "keyboard" }, default2 = { "+y", "mouse axis" },
}

It will define you controls "up" and "down" to be accessed later, and sets up two defaults for each controls, one with keyboard only control and another with mouse only. You can then use defined defaults to e.g. restore controls to default, or set them up as such if there's no user-edited controls.

Obtaining the values

This is done really easy: you simply access your control class "current" or "previous" table's child named as your defined control.

if control.current.up > 0 then player.y = player.y - 100 * dt 
elseif control.current.down > 0 then player.y = player.y + 100 * dt

These variables (except for mouse axis) contain decimal values 0..1 which you can use for analog control. Mouse axis-bound variables would store pretty arbitrary non-negative numbers, which range is really arbitrary, only influenced by mouse factor.

The library also have effecient getters and setters for that, but you are strongly discouraged to use them.

Updating controls

You simply put update function to your "love.update" callback, and that's it. It is suggested to put it to beginning of the function. Placing it to other callbacks, such as "love.keypressed" is not necessary at all due to LÖVE's way of handling them.

Enabling user to edit controls

Advanced features

Functions

Enums

See also