new Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame)
Create a new Button
object. A Button is a special type of Sprite that is set-up to handle Pointer events automatically. The four states a Button responds to are:
'Over' - when the Pointer moves over the Button. This is also commonly known as 'hover'.
'Out' - when the Pointer that was previously over the Button moves out of it.
'Down' - when the Pointer is pressed down on the Button. I.e. touched on a touch enabled device or clicked with the mouse.
'Up' - when the Pointer that was pressed down on the Button is released again.
You can set a unique texture frame and Sound for any of these states.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
game |
Phaser.Game | Current game instance. |
|
x |
number |
<optional> |
X position of the Button. |
y |
number |
<optional> |
Y position of the Button. |
key |
string |
<optional> |
The image key as defined in the Game.Cache to use as the texture for this Button. |
callback |
function |
<optional> |
The function to call when this Button is pressed. |
callbackContext |
object |
<optional> |
The context in which the callback will be called (usually 'this'). |
overFrame |
string | number |
<optional> |
This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. |
outFrame |
string | number |
<optional> |
This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. |
downFrame |
string | number |
<optional> |
This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. |
- Source:
Members
-
forceOut
-
When the Button is clicked you can optionally force the state to "out".
- Default Value:
- true
- Source:
Properties:
Name Type Description forceOut
boolean -
freezeFrames
-
- Source:
Properties:
Name Type Description freezeFrames
boolean When true the Button will cease to change texture frame on all events (over, out, up, down).
-
onDownSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onDownSound
Phaser.Sound The Sound to be played when this Buttons Down state is activated.
-
onDownSoundMarker
-
- Source:
Properties:
Name Type Description onDownSoundMarker
string The Sound Marker used in conjunction with the onDownSound.
-
onInputDown
-
- Source:
Properties:
Name Type Description onInputDown
Phaser.Signal The Signal (or event) dispatched when this Button is in an Down state.
-
onInputOut
-
- Source:
Properties:
Name Type Description onInputOut
Phaser.Signal The Signal (or event) dispatched when this Button is in an Out state.
-
onInputOver
-
- Source:
Properties:
Name Type Description onInputOver
Phaser.Signal The Signal (or event) dispatched when this Button is in an Over state.
-
onInputUp
-
- Source:
Properties:
Name Type Description onInputUp
Phaser.Signal The Signal (or event) dispatched when this Button is in an Up state.
-
onOutSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onOutSound
Phaser.Sound The Sound to be played when this Buttons Out state is activated.
-
onOutSoundMarker
-
- Source:
Properties:
Name Type Description onOutSoundMarker
string The Sound Marker used in conjunction with the onOutSound.
-
onOverSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onOverSound
Phaser.Sound The Sound to be played when this Buttons Over state is activated.
-
onOverSoundMarker
-
- Source:
Properties:
Name Type Description onOverSoundMarker
string The Sound Marker used in conjunction with the onOverSound.
-
onUpSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onUpSound
Phaser.Sound The Sound to be played when this Buttons Up state is activated.
-
onUpSoundMarker
-
- Source:
Properties:
Name Type Description onUpSoundMarker
string The Sound Marker used in conjunction with the onUpSound.
-
type
-
- Source:
Properties:
Name Type Description type
number The Phaser Object Type.
Methods
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointer
Phaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointer
Phaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointer
Phaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointer
Phaser.Pointer The Pointer that activated the Button.
- Source:
-
setDownSound(sound, marker)
-
The Sound to be played when a Pointer clicks on this Button.
Parameters:
Name Type Argument Description sound
Phaser.Sound The Sound that will be played.
marker
string <optional>
A Sound Marker that will be used in the playback.
- Source:
-
setFrames(overFrame, outFrame, downFrame)
-
Used to manually set the frames that will be used for the different states of the button exactly like setting them in the constructor.
Parameters:
Name Type Argument Description overFrame
string | number <optional>
This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
outFrame
string | number <optional>
This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
downFrame
string | number <optional>
This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
- Source:
-
setOutSound(sound, marker)
-
The Sound to be played when a Pointer moves out of this Button.
Parameters:
Name Type Argument Description sound
Phaser.Sound The Sound that will be played.
marker
string <optional>
A Sound Marker that will be used in the playback.
- Source:
-
setOverSound(sound, marker)
-
The Sound to be played when a Pointer moves over this Button.
Parameters:
Name Type Argument Description sound
Phaser.Sound The Sound that will be played.
marker
string <optional>
A Sound Marker that will be used in the playback.
- Source:
-
setSounds(overSound, overMarker, downSound, downMarker, outSound, outMarker, upSound, upMarker)
-
Sets the sounds to be played whenever this Button is interacted with. Sounds can be either full Sound objects, or markers pointing to a section of a Sound object. The most common forms of sounds are 'hover' effects and 'click' effects, which is why the order of the parameters is overSound then downSound. Call this function with no parameters at all to reset all sounds on this Button.
Parameters:
Name Type Argument Description overSound
Phaser.Sound <optional>
Over Button Sound.
overMarker
string <optional>
Over Button Sound Marker.
downSound
Phaser.Sound <optional>
Down Button Sound.
downMarker
string <optional>
Down Button Sound Marker.
outSound
Phaser.Sound <optional>
Out Button Sound.
outMarker
string <optional>
Out Button Sound Marker.
upSound
Phaser.Sound <optional>
Up Button Sound.
upMarker
string <optional>
Up Button Sound Marker.
- Source:
-
setUpSound(sound, marker)
-
The Sound to be played when a Pointer clicks on this Button.
Parameters:
Name Type Argument Description sound
Phaser.Sound The Sound that will be played.
marker
string <optional>
A Sound Marker that will be used in the playback.
- Source: