Add-on for first person applications.
It makes creating FPS applications, binding controls and
controlling character movement easier.
- Source:
Summary
Members
Methods
- add_new_state() → {CharacterState}
- add_state(new_state, enabled_transitions, change_state_cb)
- bind_action(action_type, action_controls, action_cb)
- disable_fps_controls(characteropt, elemopt)
- enable_fps_controls(optionsopt)
- freeze_movements()
- get_cam_sensitivity()
- get_cam_smooth_factor()
- get_character_state() → {CharacterState}
- is_character_locked()
- lock_character()
- set_cam_sensitivity(value)
- set_cam_smooth_factor(value)
- set_plock_disable_cb(callback)
- set_plock_enable_cb(callback)
- set_rotation_cb(rotation_cb)
- set_state_change_cb(state_id, callback)
- switch_state(state)
- unfreeze_movements()
- unlock_character()
Type Definitions
- ChangeStateCallback(old_state_id, new_state_id)
- CharMotionCallback(forw_back, right_left)
- CharRotationCallback(character, x, y)
- PlockCallback(elem)
Detailed Description
Members
AT_CONTINUOUS
An input type detecting a continuous user action,
e.g. a held down button, mouse movement, gamepad stick tilt etc.
- Source:
AT_PRESSED
An input type detecting a discrete user action, e.g. button press.
- Source:
AT_RELEASED
An input type detecting a discrete user action, e.g. button release.
- Source:
CS_CLIMB
Character state defining that character is in climb-mode.
Type:
- Source:
CS_FLY
Character state defining that character is in fly-mode.
Type:
- Source:
CS_RUN
Character state defining that character is in run-mode.
Type:
- Source:
CS_STAY
Character state defining that character is staying.
Type:
- Source:
CS_WALK
Character state defining that character is in walk-mode.
Type:
- Source:
Methods
add_new_state() → {CharacterState}
Add new character's state.
Returns:
Character's new state
- Type
- CharacterState
- Source:
Example
var m_fps = require("fps");
var new_state = m_fps.add_new_state();
add_state(new_state, enabled_transitions, change_state_cb)
Add new character's state to its state machine.
Parameters:
Name | Type | Description |
---|---|---|
new_state |
CharacterState | Character's new state |
enabled_transitions |
Array.<CharacterState> | Enabled transitions to another states |
change_state_cb |
ChangeStateCallback | Callback function |
- Source:
Example
var m_fps = require("fps");
var new_state = m_fps.add_new_state();
var state_changing_cb = function(old_state_id, new_state_id) {
console.log(old_state_id, new_state_id);
}
m_fps.add_state(new_state, [m_fps.CS_WALK, m_fps.CS_RUN], state_changing_cb);
bind_action(action_type, action_controls, action_cb)
Bind action callback to user controls. This allows to set and define an additional
action to an event and set the conditions to when and how the event happens.
Parameters:
Name | Type | Description |
---|---|---|
action_type |
number | Type of action |
action_controls |
Array | Array of sensor types |
action_cb |
function | Function which applies logic |
- Source:
Example
var m_ctl = require("controls");
var m_fps = require("fps");
var m_input = require("input");
var action_cb = function(value) {
console.log(value);
};
// bind custom callback to be executed after pressing the W key or one of the gamepad
// buttons or after clicking/touching the html element with the "forward_button_id" id
m_fps.bind_action(m_fps.AT_PRESSED, [m_ctl.KEY_W, m_input.GMPD_BUTTON_12,
"forward_button_id"], action_cb);
disable_fps_controls(characteropt, elemopt)
Disable FPS controls.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
character |
Object3D |
<optional> |
The result of the get_first_character() method call | Character |
elem |
HTMLElement |
<optional> |
Canvas container element | HTML element to add event listeners to |
- Source:
Example
var m_fps = require("fps");
m_fps.disable_fps_controls();
enable_fps_controls(optionsopt)
Enable FPS controls. This sets keyboard, gamepad and mouse controls.
VR is also plug-and-play ready.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
{} | Initialization options.
Properties
|
- Source:
Example
var m_fps = require("fps");
var character = m_scene.get_first_character();
var move_cb = function(forw_back, right_left) {
console.log(forw_back, right_left);
}
m_fps.enable_fps_controls(character, null, move_cb);
freeze_movements()
Freeze character's movements.
- Source:
Example
var m_fps = require("fps");
m_fps.freeze_movements();
get_cam_sensitivity()
Get character's camera mouse sensitivity
- Source:
Example
var m_fps = require("fps");
var sens = m_fps.get_cam_sensitivity();
get_cam_smooth_factor()
Set character's camera smooth behavior
- Source:
Example
var m_fps = require("fps");
var smooth_factor = m_fps.get_cam_smooth_factor();
get_character_state() → {CharacterState}
Get character's current state.
Returns:
Character's current state
- Type
- CharacterState
- Source:
Example
var m_fps = require("fps");
var curr_state = m_fps.get_character_state();
if (curr_state == m_fps.CS_RUN)
console.log("Character is running");
is_character_locked()
Check if character's state changing is locked.
- Source:
Example
var m_fps = require("fps");
if (m_fps.is_character_locked())
console.log("character is locked");
lock_character()
Lock character's state changing.
- Source:
Example
var m_fps = require("fps");
m_fps.lock_character();
set_cam_sensitivity(value)
Set character's camera mouse sensitivity
Parameters:
Name | Type | Description |
---|---|---|
value |
number | Sensitivity |
- Source:
Example
var m_fps = require("fps");
m_fps.set_cam_sensitivity(80);
set_cam_smooth_factor(value)
Set character's camera smooth behavior
Parameters:
Name | Type | Description |
---|---|---|
value |
number | Smooth factor |
- Source:
Example
var m_fps = require("fps");
m_fps.set_cam_smooth_factor(0.2);
set_plock_disable_cb(callback)
Set pointerlock callback function, which is called when pointerlock is disabled
Parameters:
Name | Type | Description |
---|---|---|
callback |
PlockCallback | Callback function |
- Source:
Example
var m_fps = require("fps");
var cb = function(element) {
console.log("pointerlock is disabled");
}
m_fps.set_plock_disable_cb(cb);
set_plock_enable_cb(callback)
Set pointerlock callback function, which is called when pointerlock is enabled
Parameters:
Name | Type | Description |
---|---|---|
callback |
PlockCallback | Callback function |
- Source:
Example
var m_fps = require("fps");
var cb = function(element) {
console.log("pointerlock is enabled");
}
m_fps.set_plock_enable_cb(cb);
set_rotation_cb(rotation_cb)
Set character rotation callback.
Parameters:
Name | Type | Description |
---|---|---|
rotation_cb |
CharRotationCallback | Character's rotation callback |
- Source:
Example
var m_fps = require("fps");
m_fps.set_rotation_cb(function(char, rot_x, rot_y) {});
set_state_change_cb(state_id, callback)
Set character state changing callback function.
Parameters:
Name | Type | Description |
---|---|---|
state_id |
number | State ID |
callback |
ChangeStateCallback | Callback function |
- Source:
Example
var m_fps = require("fps");
var state_changing_cb = function(old_state_id, new_state_id) {
console.log(old_state_id, new_state_id);
}
m_fps.set_state_change_cb(m_fps.CS_WALK, state_changing_cb);
switch_state(state)
Switch character's state.
Parameters:
Name | Type | Description |
---|---|---|
state |
CharacterState | Character's state |
- Source:
Example
var m_fps = require("fps");
m_fps.switch_state(m_fps.CS_WALK);
unfreeze_movements()
Unfreeze character's movements.
- Source:
Example
var m_fps = require("fps");
m_fps.unfreeze_movements();
unlock_character()
Unlock character's state changing.
- Source:
Example
var m_fps = require("fps");
m_fps.unlock_character();
Type Definitions
ChangeStateCallback(old_state_id, new_state_id)
Function which is called when the given ID state is changed.
Parameters:
Name | Type | Description |
---|---|---|
old_state_id |
number | Previous state ID. |
new_state_id |
number | New state ID. |
- Source:
CharMotionCallback(forw_back, right_left)
Function which is called when character changes his movement direction.
Parameters:
Name | Type | Description |
---|---|---|
forw_back |
number | Forward/backward direction (can be -1, 1 or 0). |
right_left |
number | Right/left direction (can be -1, 1 or 0). |
- Source:
CharRotationCallback(character, x, y)
Callback for characters/camera rotation
Parameters:
Name | Type | Description |
---|---|---|
character |
Object3D | Character |
x |
number | rotation around X-axis in radians |
y |
number | rotation around Y-axis in radians |
- Source:
PlockCallback(elem)
Function which is called when pointerlock state was changed.
Parameters:
Name | Type | Description |
---|---|---|
elem |
HTMLElement | HTML element, which required pointerlock |
- Source: