Class: Button

Phaser. Button

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.

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".

Properties:
Name Type Description
forceOut boolean
Default Value:
  • false
Source:

freezeFrames

Properties:
Name Type Description
freezeFrames boolean

When true the Button will cease to change texture frame on all events (over, out, up, down).

Source:

onDownSound

Properties:
Name Type Description
onDownSound Phaser.Sound

The Sound to be played when this Buttons Down state is activated.

Default Value:
  • null
Source:

onDownSoundMarker

Properties:
Name Type Description
onDownSoundMarker string

The Sound Marker used in conjunction with the onDownSound.

Source:

onInputDown

Properties:
Name Type Description
onInputDown Phaser.Signal

The Signal (or event) dispatched when this Button is in an Down state.

Source:

onInputOut

Properties:
Name Type Description
onInputOut Phaser.Signal

The Signal (or event) dispatched when this Button is in an Out state.

Source:

onInputOver

Properties:
Name Type Description
onInputOver Phaser.Signal

The Signal (or event) dispatched when this Button is in an Over state.

Source:

onInputUp

Properties:
Name Type Description
onInputUp Phaser.Signal

The Signal (or event) dispatched when this Button is in an Up state.

Source:

onOutSound

Properties:
Name Type Description
onOutSound Phaser.Sound

The Sound to be played when this Buttons Out state is activated.

Default Value:
  • null
Source:

onOutSoundMarker

Properties:
Name Type Description
onOutSoundMarker string

The Sound Marker used in conjunction with the onOutSound.

Source:

onOverSound

Properties:
Name Type Description
onOverSound Phaser.Sound

The Sound to be played when this Buttons Over state is activated.

Default Value:
  • null
Source:

onOverSoundMarker

Properties:
Name Type Description
onOverSoundMarker string

The Sound Marker used in conjunction with the onOverSound.

Source:

onUpSound

Properties:
Name Type Description
onUpSound Phaser.Sound

The Sound to be played when this Buttons Up state is activated.

Default Value:
  • null
Source:

onUpSoundMarker

Properties:
Name Type Description
onUpSoundMarker string

The Sound Marker used in conjunction with the onUpSound.

Source:

type

Properties:
Name Type Description
type number

The Phaser Object Type.

Source:

Methods

clearFrames()

Clears all of the frames set on this Button.

Source:

<protected> onInputOverHandler(sprite, pointer)

Internal function that handles input events.

Parameters:
Name Type Description
sprite Phaser.Button

The Button that the event occured on.

pointer Phaser.Pointer

The Pointer that activated the Button.

Source:

<protected> onInputOverHandler(sprite, pointer)

Internal function that handles input events.

Parameters:
Name Type Description
sprite Phaser.Button

The Button that the event occured on.

pointer Phaser.Pointer

The Pointer that activated the Button.

Source:

<protected> onInputOverHandler(sprite, pointer)

Internal function that handles input events.

Parameters:
Name Type Description
sprite Phaser.Button

The Button that the event occured on.

pointer Phaser.Pointer

The Pointer that activated the Button.

Source:

<protected> onInputOverHandler(sprite, pointer)

Internal function that handles input events.

Parameters:
Name Type Description
sprite Phaser.Button

The Button that the event occured on.

pointer Phaser.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
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, upFrame)

Used to manually set the frames that will be used for the different states of the Button.

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.

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:

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:

<protected> setState(newState)

Internal function that handles Button state changes.

Parameters:
Name Type Description
newState number

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
sound Phaser.Sound

The Sound that will be played.

marker string <optional>

A Sound Marker that will be used in the playback.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Wed Feb 05 2014 06:28:26 GMT-0000 (GMT) using the DocStrap template.