new DeviceButton(parent, buttonCode)
DeviceButtons belong to both Phaser.Pointer
and Phaser.SinglePad
(Gamepad) instances.
For Pointers they represent the various buttons that can exist on mice and pens, such as the left button, right button, middle button and advanced buttons like back and forward.
Access them via Pointer.leftbutton
, Pointer.rightButton
and so on.
On Gamepads they represent all buttons on the pad: from shoulder buttons to action buttons.
At the time of writing this there are device limitations you should be aware of:
- On Windows, if you install a mouse driver, and its utility software allows you to customize button actions (e.g., IntelliPoint and SetPoint), the middle (wheel) button, the 4th button, and the 5th button might not be set, even when they are pressed.
- On Linux (GTK), the 4th button and the 5th button are not supported.
- On Mac OS X 10.5 there is no platform API for implementing any advanced buttons.
Parameters:
Name | Type | Description |
---|---|---|
parent |
Phaser.Pointer | Phaser.SinglePad | A reference to the parent of this button. Either a Pointer or a Gamepad. |
buttonCode |
number | The button code this DeviceButton is responsible for. |
- Source - input/DeviceButton.js, line 31
Members
-
altKey :boolean
-
True if the alt key was held down when this button was last pressed or released. Not supported on Gamepads.
- Default Value:
- false
- Source - input/DeviceButton.js, line 96
-
buttonCode :number
-
The buttoncode of this button if a Gamepad, or the DOM button event value if a Pointer.
- Source - input/DeviceButton.js, line 123
-
ctrlKey :boolean
-
True if the control key was held down when this button was last pressed or released. Not supported on Gamepads.
- Default Value:
- false
- Source - input/DeviceButton.js, line 112
-
duration :number
-
If the button is down this value holds the duration of that button press and is constantly updated. If the button is up it holds the duration of the previous down session. The value is stored in milliseconds.
- Default Value:
- 0
- Source - input/DeviceButton.js, line 74
-
<readonly> duration :number
-
How long the button has been held down. If not currently down it returns -1.
- Source - input/DeviceButton.js, line 311
-
event :object
-
The DOM event that caused the change in button state.
- Default Value:
- null
- Source - input/DeviceButton.js, line 47
-
game :Phaser.Game
-
A reference to the currently running game.
- Source - input/DeviceButton.js, line 41
-
isDown :boolean
-
The "down" state of the button.
- Default Value:
- false
- Source - input/DeviceButton.js, line 53
-
isUp :boolean
-
The "up" state of the button.
- Default Value:
- true
- Source - input/DeviceButton.js, line 59
-
onDown :Phaser.Signal
-
This Signal is dispatched every time this DeviceButton is pressed down. It is only dispatched once (until the button is released again). When dispatched it sends 2 arguments: A reference to this DeviceButton and the value of the button.
- Source - input/DeviceButton.js, line 131
-
onFloat :Phaser.Signal
-
Gamepad only. This Signal is dispatched every time this DeviceButton changes floating value (between, but not exactly, 0 and 1). When dispatched it sends 2 arguments: A reference to this DeviceButton and the value of the button.
- Source - input/DeviceButton.js, line 147
-
onUp :Phaser.Signal
-
This Signal is dispatched every time this DeviceButton is released from a down state. It is only dispatched once (until the button is pressed again). When dispatched it sends 2 arguments: A reference to this DeviceButton and the value of the button.
- Source - input/DeviceButton.js, line 139
-
parent :Phaser.Pointer|Phaser.SinglePad
-
A reference to the Pointer or Gamepad that owns this button.
Type:
- Source - input/DeviceButton.js, line 36
-
repeats :number
-
Gamepad only. If a button is held down this holds down the number of times the button has 'repeated'.
- Default Value:
- 0
- Source - input/DeviceButton.js, line 88
-
shiftKey :boolean
-
True if the shift key was held down when this button was last pressed or released. Not supported on Gamepads.
- Default Value:
- false
- Source - input/DeviceButton.js, line 104
-
timeDown :number
-
The timestamp when the button was last pressed down.
- Default Value:
- 0
- Source - input/DeviceButton.js, line 65
-
timeUp :number
-
The timestamp when the button was last released.
- Default Value:
- 0
- Source - input/DeviceButton.js, line 80
-
value :number
-
Button value. Mainly useful for checking analog buttons (like shoulder triggers) on Gamepads.
- Default Value:
- 0
- Source - input/DeviceButton.js, line 118
Methods
-
destroy()
-
Destroys this DeviceButton, this disposes of the onDown, onUp and onFloat signals and clears the parent and game references.
- Source - input/DeviceButton.js, line 290
-
justPressed(duration) → {boolean}
-
Returns the "just pressed" state of this button. Just pressed is considered true if the button was pressed down within the duration given (default 250ms).
Parameters:
Name Type Argument Default Description duration
number <optional>
250 The duration in ms below which the button is considered as being just pressed.
Returns:
boolean -True if the button is just pressed otherwise false.
- Source - input/DeviceButton.js, line 238
-
justReleased(duration) → {boolean}
-
Returns the "just released" state of this button. Just released is considered as being true if the button was released within the duration given (default 250ms).
Parameters:
Name Type Argument Default Description duration
number <optional>
250 The duration in ms below which the button is considered as being just released.
Returns:
boolean -True if the button is just released otherwise false.
- Source - input/DeviceButton.js, line 254
-
<internal> padFloat(value)
-
Called automatically by Phaser.SinglePad.
Parameters:
Name Type Description value
number Button value
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - input/DeviceButton.js, line 223
-
reset()
-
Resets this DeviceButton, changing it to an isUp state and resetting the duration and repeats counters.
- Source - input/DeviceButton.js, line 270
-
<internal> start(event, value)
-
Called automatically by Phaser.Pointer and Phaser.SinglePad. Handles the button down state.
Parameters:
Name Type Argument Description event
object <optional>
The DOM event that triggered the button change.
value
number <optional>
The button value. Only get for Gamepads.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - input/DeviceButton.js, line 153
-
<internal> stop(event, value)
-
Called automatically by Phaser.Pointer and Phaser.SinglePad. Handles the button up state.
Parameters:
Name Type Argument Description event
object <optional>
The DOM event that triggered the button change.
value
number <optional>
The button value. Only get for Gamepads.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - input/DeviceButton.js, line 189