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
-
freezeFrames
-
- Source:
Properties:
Name Type Description freezeFramesboolean 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 onDownSoundPhaser.Sound The Sound to be played when this Buttons Down state is activated.
-
onDownSoundMarker
-
- Source:
Properties:
Name Type Description onDownSoundMarkerstring The Sound Marker used in conjunction with the onDownSound.
-
onInputDown
-
- Source:
Properties:
Name Type Description onInputDownPhaser.Signal The Signal (or event) dispatched when this Button is in an Down state.
-
onInputOut
-
- Source:
Properties:
Name Type Description onInputOutPhaser.Signal The Signal (or event) dispatched when this Button is in an Out state.
-
onInputOver
-
- Source:
Properties:
Name Type Description onInputOverPhaser.Signal The Signal (or event) dispatched when this Button is in an Over state.
-
onInputUp
-
- Source:
Properties:
Name Type Description onInputUpPhaser.Signal The Signal (or event) dispatched when this Button is in an Up state.
-
onOutSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onOutSoundPhaser.Sound The Sound to be played when this Buttons Out state is activated.
-
onOutSoundMarker
-
- Source:
Properties:
Name Type Description onOutSoundMarkerstring The Sound Marker used in conjunction with the onOutSound.
-
onOverSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onOverSoundPhaser.Sound The Sound to be played when this Buttons Over state is activated.
-
onOverSoundMarker
-
- Source:
Properties:
Name Type Description onOverSoundMarkerstring The Sound Marker used in conjunction with the onOverSound.
-
onUpSound
-
- Default Value:
- null
- Source:
Properties:
Name Type Description onUpSoundPhaser.Sound The Sound to be played when this Buttons Up state is activated.
-
onUpSoundMarker
-
- Source:
Properties:
Name Type Description onUpSoundMarkerstring The Sound Marker used in conjunction with the onUpSound.
-
type
-
- Source:
Properties:
Name Type Description typenumber The Phaser Object Type.
Methods
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description pointerPhaser.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 soundPhaser.Sound The Sound that will be played.
markerstring <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 overFramestring | 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.
outFramestring | 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.
downFramestring | 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 soundPhaser.Sound The Sound that will be played.
markerstring <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 soundPhaser.Sound The Sound that will be played.
markerstring <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 overSoundPhaser.Sound <optional>
Over Button Sound.
overMarkerstring <optional>
Over Button Sound Marker.
downSoundPhaser.Sound <optional>
Down Button Sound.
downMarkerstring <optional>
Down Button Sound Marker.
outSoundPhaser.Sound <optional>
Out Button Sound.
outMarkerstring <optional>
Out Button Sound Marker.
upSoundPhaser.Sound <optional>
Up Button Sound.
upMarkerstring <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 soundPhaser.Sound The Sound that will be played.
markerstring <optional>
A Sound Marker that will be used in the playback.
- Source: