Strict Standards: Declaration of action_plugin_safefnrecode::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /home/impact/public_html/docs/lib/plugins/safefnrecode/action.php on line 14

Strict Standards: Declaration of action_plugin_popularity::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /home/impact/public_html/docs/lib/plugins/popularity/action.php on line 57

Strict Standards: Declaration of action_plugin_wrap::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /home/impact/public_html/docs/lib/plugins/wrap/action.php on line 125

Warning: Cannot modify header information - headers already sent by (output started at /home/impact/public_html/docs/lib/plugins/safefnrecode/action.php:14) in /home/impact/public_html/docs/inc/auth.php on line 352

Warning: Cannot modify header information - headers already sent by (output started at /home/impact/public_html/docs/lib/plugins/safefnrecode/action.php:14) in /home/impact/public_html/docs/inc/actions.php on line 180

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/impact/public_html/docs/lib/plugins/safefnrecode/action.php:14) in /home/impact/public_html/includes/header.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/impact/public_html/docs/lib/plugins/safefnrecode/action.php:14) in /home/impact/public_html/includes/header.php on line 2
Point of Impact
 Report a Bug

SIGN IN!

Community Documentation Wiki

Input

Defined in Module impact.input, inherits from ig.Class

Synopsis

// On game start
ig.input.bind( ig.KEY.UP_ARROW, 'jump' );
 
// In your game's or entity's update() method
if( ig.input.pressed('jump') ) {
    this.vel.y = -100;
}

Description

ig.Input handles all Keyboard and Mouse input.

You can bind keys to specific actions and then ask if one of these actions is currently held down (.state()) or was just pressed down after the last frame (.pressed()).

Note that an instance of ig.Input is automatically created at ig.input (lowercase) by the ig.main() function.

Properties

.mouse.x, .mouse.y

Position of the mouse cursor on your game screen in pixels. Note that this position is only updated when at least one mouse button is bound to an action.

If you haven't bound any mouse button, you can call .initMouse() yourself once, to start capturing mouse input.

Methods

.bind( key, action )

Bind a Keyboard or Mouse button to an action. action is a string or integer, identifying the action in your game. Call this function for each button and action pair at the start of your game.

key can be anything of ig.KEY.*.

Several buttons can be bound to the same action, but a button can not be bound to several actions.

// Binds both, UP_ARROW and SPACE, to the same action
ig.input.bind( ig.KEY.UP_ARROW, 'jump' );
ig.input.bind( ig.KEY.SPACE, 'jump' );

.bindTouch( selector, action )

Bind an HTML element to issue the specified action when the element is touched. This will only work for devices that implement the touchstart and touchend events - currently iOS and Android devices.

The element specified by the selector must already be present. It will not be created by Impact. selector can only be an id-selector; e.g. '#button'.

// Bind the <div id="button1"></div> element to the "jump" action
ig.input.bindTouch( '#button1', 'jump' );

.initMouse()

Start capturing mouse input. This method is automatically called as soon as one of the mouse buttons has been bound.

.pressed( action )

Returns true if one of the buttons bound to the specified action was just pressed down, false otherwise.

In contrast to .state(), this method only returns true once for each button press. You can use this for example if you want the user to repeatedly press a button to shoot instead of having “autofire”.

.state( action )

Returns true if one of the buttons bound to the specified action is currently pressed down, false otherwise.

.unbind( key )

Unbind a Keyboard or Mouse button from its current action.

key can be anything of ig.KEY.*. See below for a list.

.unbindAll()

Unbind all Keyboard, Mouse and Touch buttons.

Mouse and Keyboard Constants

ig.KEY.MOUSE1
ig.KEY.MOUSE2
ig.KEY.MWHEEL_UP
ig.KEY.MWHEEL_DOWN
 
ig.KEY.BACKSPACE
ig.KEY.TAB
ig.KEY.ENTER
ig.KEY.PAUSE
ig.KEY.CAPS
ig.KEY.ESC
ig.KEY.SPACE
ig.KEY.PAGE_UP
ig.KEY.PAGE_DOWN
ig.KEY.END
ig.KEY.HOME
ig.KEY.LEFT_ARROW
ig.KEY.UP_ARROW
ig.KEY.RIGHT_ARROW
ig.KEY.DOWN_ARROW
ig.KEY.INSERT
ig.KEY.DELETE
ig.KEY.0
ig.KEY.1
ig.KEY.2
ig.KEY.3
ig.KEY.4
ig.KEY.5
ig.KEY.6
ig.KEY.7
ig.KEY.8
ig.KEY.9
ig.KEY.A
ig.KEY.B
ig.KEY.C
ig.KEY.D
ig.KEY.E
ig.KEY.F
ig.KEY.G
ig.KEY.H
ig.KEY.I
ig.KEY.J
ig.KEY.K
ig.KEY.L
ig.KEY.M
ig.KEY.N
ig.KEY.O
ig.KEY.P
ig.KEY.Q
ig.KEY.R
ig.KEY.S
ig.KEY.T
ig.KEY.U
ig.KEY.V
ig.KEY.W
ig.KEY.X
ig.KEY.Y
ig.KEY.Z
ig.KEY.NUMPAD_0
ig.KEY.NUMPAD_1
ig.KEY.NUMPAD_2
ig.KEY.NUMPAD_3
ig.KEY.NUMPAD_4
ig.KEY.NUMPAD_5
ig.KEY.NUMPAD_6
ig.KEY.NUMPAD_7
ig.KEY.NUMPAD_8
ig.KEY.NUMPAD_9
ig.KEY.MULTIPLY
ig.KEY.ADD
ig.KEY.SUBSTRACT
ig.KEY.DECIMAL
ig.KEY.DIVIDE
ig.KEY.F1
ig.KEY.F2
ig.KEY.F3
ig.KEY.F4
ig.KEY.F5
ig.KEY.F6
ig.KEY.F7
ig.KEY.F8
ig.KEY.F9
ig.KEY.F10
ig.KEY.F11
ig.KEY.F12
ig.KEY.SHIFT
ig.KEY.CTRL
ig.KEY.ALT
ig.KEY.PLUS
ig.KEY.COMMA
ig.KEY.MINUS
ig.KEY.PERIOD
Ready to get to the point?

Your Email will remain private and is only used for good. We promise!


Please use only letters, numbers or underscores.

SIGN UP!