Difference between revisions of "Common Organization of Controls Kit Callbacks"

(Created page with "The library provides the functionality of envoking callbacks when certain action happens, just like love.keypressed or love.mousepressed callbacks. == Basics == Following callbac...")
 
 
(No difference)

Latest revision as of 12:58, 1 September 2013

The library provides the functionality of envoking callbacks when certain action happens, just like love.keypressed or love.mousepressed callbacks.

Basics

Following callbacks are defined:

cock.controlcaptured = function ( id, longdata )
cock.controlpressed = function ( id, map, value )
cock.controlreleased = function ( id, map, value )
cock.controlpeaked = function ( id, map, value )
cock.controlzeroed = function ( id, map, value )
cock.controlchanged = function ( id, map, value )
string id
ID of the object that issued the callback.
string map
Control map that triggered the callback.
number value
Readings on the input.
string longdata
Programmatically arranged data that sums up all info about captured user input. It is used because all the fields wouldn't fit into callbacks' 4 available slots. You must use cock.explodeCapturedData helper function to convert it to meaningful data. You can pass it "as is" to the cock.bind function.
  • controlcaptued called when in input mode some user input was captured
  • controlpressed called when readings went above 0.5
  • controlreleased called when readings went below 0.5
  • controlpeaked called when readings reached 1.0 (or above)
  • controlzeroed called when readings dropped to 0.0
  • controlchanged called whenever reading is changed

Details

Because this system generates vastly more calls than regular LÖVE callbacks system, all callbacks are disabled by default. You must enable them with cock.setCallbacks except "controlcaptured", which is set at each cock.setCapture call.

Every callback is supplied with ID of the object that issued the callback. You may not need it, but if you have multiple control objects, that will help you figure which one has the input activity. To get corresponding control object table, you can use cock.find function.

If your game uses user-defined controls via capturing them, then your most important callback is "controlcaptured". In it, you would decide whether or not you want to use the captured data, alter it, discard or actually bind, and finally perform other related actions. E.g. you may check whether or not supplied key is already binded elsewhere and prompt user for override or cancel capture.

All other callbacks are used the same way as LÖVE's callbacks.

See also