Archive for May, 2009
I added a new common library to TSTK for actionMaps.
This common library adds two new (user) methods:
- ActionMap::bindMulti( %this, %device, %action, %object, %callback );
- ActionMap::unbindMulti( %this, %device, %action, %object, %callback );
The “bindMulti()” function allows you to bind the same input (key, button, etc.) to more than one callback. Typically, you can only bind one function (or object + method) to any specific input. However, in some cases it is useful to have the ability to bind the same input to more than one function (or object + method). For example. If you wanted to allow a key press to fire multiple weapons, you could simply use “bindMulti()” to bind the same key to each of the callbacks for each different weapon (see code sample below):
function firstWeapon::fire( %this, %val ) {
// ... more code
}
function secondWeapon::fireMe( %this, %val ) {
// ... more code
}
function thirdWeapon::fireMeToo( %this, %val ) {
// ... more code
}
// ... more code
moveMap.bindMulti( "Keyboard", "space", firstWeapon, "fire" );
moveMap.bindMulti( "Keyboard", "space", secondWeapon, "fireMe" );
moveMap.bindMulti( "Keyboard", "space", thirdWeapon, "fireMeToo" );
In the above example, three different weapons and their respective callbacks have been mapped to the same key (the spacebar).
I hope you find this useful.
Cheers,
edo
PS – I’m still working on getting a faster site. Sorry for the slowwwwness!