new Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)
Parameters:
| Name | Type | Argument | Default | Description |
|---|---|---|---|---|
game |
Phaser.Game | Current game instance. |
||
x |
number |
<optional> |
0 | X position of the Button. |
y |
number |
<optional> |
0 | 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. |
|
upFrame |
string | number |
<optional> |
This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name. |
- Source:
Members
-
forceOut
-
When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up".
- Default Value:
- false
- Source:
Properties:
Name Type Description forceOutboolean -
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
-
clearFrames()
-
Clears all of the frames set on this Button.
- Source:
-
<protected> onInputDownHandler(sprite, pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description spritePhaser.Button The Button that the event occured on.
pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOutHandler(sprite, pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description spritePhaser.Button The Button that the event occured on.
pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputOverHandler(sprite, pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description spritePhaser.Button The Button that the event occured on.
pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
<protected> onInputUpHandler(sprite, pointer)
-
Internal function that handles input events.
Parameters:
Name Type Description spritePhaser.Button The Button that the event occured on.
pointerPhaser.Pointer The Pointer that activated the Button.
- Source:
-
setDownSound(sound, marker)
-
The Sound to be played when a Pointer presses down 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, upFrame)
-
Used to manually set the frames that will be used for the different states of the Button.
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.
upFramestring | number <optional>
This is the frame or frameName that will be set when this button is in an up 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:
-
<protected> setState(newState)
-
Internal function that handles Button state changes.
Parameters:
Name Type Description newStatenumber The new State of the Button.
- Source:
-
setUpSound(sound, marker)
-
The Sound to be played when a Pointer has pressed down and is released from 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: