Event.InputMapper Class
InputMapper is a virtual event provider used to redirect event under an other event.
It allow to create custom events (user-defined), following others eventProviders. Its role is to act as an interface, hiding real event which can be changed without the user noticing.
A typical utilisation is the remapping is to let the choice of controls keyboard to the player.
var keyboardEvents = new KeyboardInput();
var inputMapper = new InputMapper();
inputMapper.addEvent("ATTACK");
inputMapper.bind("ATTACK", "KEY_Q", keyboardEvents);
inputMapper.addListener("ATTACK", KeyboardInput.KEY_PRESSED, function(event, value, provider) {
});
Constructor
Event.InputMapper
()
Item Index
Methods
Properties
Methods
_bindEvent
-
event
-
newValue
-
object
Callback function who bind a local event with remote event.
Parameters:
-
event
String -
newValue
Boolean | Object -
object
EventProvider
_bindListenEvent
-
event
-
newValue
-
object
Callback function who bind a local event with remote event when bindListen is run.
Parameters:
-
event
String -
newValue
Boolean | Object -
object
EventProvider
_modifyState
-
event
-
newValue
Apply a modification to an internal state variable and call listeners.
Parameters:
-
event
Stringevent name
-
newValue
the new value.
addEvent
-
name
Adding a local event.
Parameters:
-
name
String
Returns:
addListener
-
[event]
-
[value]
-
callback
add a listener.
it can listen all events or only one event variable. The listener can choose to be called for all events associated to a variable, or only when the variable is in a certain state.
Parameters:
-
[event]
String optionalname of event variable. y default, all events are caught.
-
[value]
optionalvalue expected for call the callback. By default, any value call the callback.
-
callback
Functioncallback function called with 3 parameters:
-
event
Stringevent name
-
value
new value
-
provider
EventProviderinstance of provider
-
Returns:
Example:
//myCallback will be called for each events.
provider.addListener(myCallback);
//mySecondCallback will be called only when the "A" variable obtain the state KEY_PRESSED.
provider.addListener("A", provider.KEY_PRESSED, mySecondCallback);
bindEvent
-
localEvent
-
remoteEvent
-
input
Bind a remote event to a local event.
Parameters:
-
localEvent
String -
remoteEvent
String -
input
EventProvider
bindListen
-
localEvent
-
input
-
callback
Bind a remote event to a local event by listening to the next event of input.
Parameters:
-
localEvent
String -
input
EventProvider -
callback
Function
getNoMappedEvents
()
Array
Getting a array of all no mapped local event.
Returns:
getOldState
-
name
Search the previous state of a state variable. The provider keep always one old state for each variable. It's useful for compare the difference.
Parameters:
-
name
String
Returns:
getRealEvent
-
localEvent
Getting the name of event bind with localEvent.
Parameters:
-
localEvent
String
Returns:
getState
-
name
Search the state of a state variable
Parameters:
-
name
String
Returns:
getStateList
()
String
List all variables accessible by this provider Each variable can accept listeners.
Note: return value is a reference. you should make a copy if you need to modify it.
Returns:
getType
()
String
return the EventProvider type.
Returns:
rmEvent
-
name
Removing a local event.
Parameters:
-
name
String
Returns:
rmListener
-
id
Remove a listener.
Parameters:
-
id
Numberid of the listener.
stopBindListen
()
Stop a listening of the function bindListen.
Properties
_oldValues
Array
protected
List of previous values for state variables.
this._states
and this._oldValues
share the same array index.
_states []
String
protected
List of all event variables name.
_values
Array
protected
List of values for state variables.
this._states
and this._values
share the same array index.
enable
Boolean
enable or disable this object.