springroll.pixi.Button Class

Extends PIXI.Container
Module: PIXI UI

A Multipurpose button class. It is designed to have one image, and an optional text label. The button can be a normal button or a selectable button. The button functions similarly with both EaselJS and PIXI, but slightly differently in initialization and callbacks. Use the "buttonPress" and "buttonOver" events to know about button clicks and mouse overs, respectively.

Constructor

springroll.pixi.Button

(
  • imageSettings
  • [imageSettings.priority=null] The state priority order. If omitted, defaults to ["disabled", "down", "over", "up"]. Previous versions of Button used a hard coded order: ["highlighted", "disabled", "down", "over", "selected", "up"]
  • [label=null]
  • [enabled=true]
)

Parameters:

  • imageSettings Object

    Information about the art to be used for button states, as well as if the button is selectable or not.

    • [up] Object | PIXI.Texture optional

      The texture for the up state of the button. This can be either the texture itself, or an object with 'tex' and 'label' properties.

      • [tex] PIXI.Texture | String optional
        The texture to use for the up state. If this is a string, Texture.fromImage() will be used.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [over=null] Object | PIXI.Texture optional

      The texture for the over state of the button. If omitted, uses the up state.

      • [tex] PIXI.Texture | String optional
        The texture to use for the over state. If this is a string, Texture.fromImage() will be used.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [down=null] Object | PIXI.Texture optional

      The texture for the down state of the button. If omitted, uses the up state.

      • [tex] PIXI.Texture | String optional
        The texture to use for the down state. If this is a string, Texture.fromImage() will be used.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [disabled=null] Object | PIXI.Texture optional

      The texture for the disabled state of the button. If omitted, uses the up state.

      • [tex] PIXI.Texture | String optional
        The texture to use for the disabled state. If this is a string, Texture.fromImage() will be used.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [<yourCustomState>=null] Object | PIXI.Texture optional

      The visual information about a custom state found in imageSettings.priority. Any state added this way has a property of the same name added to the button. Examples of previous states that have been moved to this system are "selected" and "highlighted".

      • [tex] PIXI.Texture | String optional
        The texture to use for your custom state. If this is a string, Texture.fromImage() will be used.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
    • [origin=null] PIXI.Point optional

      An optional offset for all button graphics, in case you want button positioning to not include a highlight glow, or any other reason you would want to offset the button art and label.

    • [scale=1] Number optional

      The scale to use for the textures. This allows smaller art assets than the designed size to be used.

  • [imageSettings.priority=null] The state priority order. If omitted, defaults to ["disabled", "down", "over", "up"]. Previous versions of Button used a hard coded order: ["highlighted", "disabled", "down", "over", "selected", "up"] Array

    .

  • [label=null] Object optional

    Information about the text label on the button. Omitting this makes the button not use a label.

    • [type] String optional

      If label.type is "bitmap", then a PIXI.extras.BitmapText text is created, otherwise a PIXI.Text is created for the label.

    • [text] String optional

      The text to display on the label.

    • [style] Object optional

      The style of the text field, in the format that PIXI.extras.BitmapText and PIXI.Text expect.

    • [x="center"] String | Number optional

      An x position to place the label text at relative to the button.

    • [y="center"] String | Number optional

      A y position to place the label text at relative to the button. If omitted, "center" is used, which attempts to vertically center the label on the button.

  • [enabled=true] Boolean optional

    Whether or not the button is initially enabled.

_addProperty

(
  • propertyName
)
private

Defined in _addProperty:535

Adds a property to the button. Setting the property sets the value in _stateFlags and calls _updateState().

Parameters:

  • propertyName String

    The property name to add to the button.

_onDown

()
private

Defined in _onDown:679

The callback for when the button receives a mouse down event.

_onOut

()
private

Defined in _onOut:666

The callback for when the mouse leaves the button area.

_onOver

()
private

Defined in _onOver:653

The callback for when the button is moused over.

_onUp

()
private

Defined in _onUp:695

The callback for when the button for when the mouse/touch is released on the button

  • only when the button was held down initially.

_onUpOutside

()
private

Defined in _onUpOutside:721

The callback for when the mouse/touch is released outside the button when the button was held down.

_updateState

() Object
private

Defined in _updateState:566

Updates back based on the current button state.

Returns:

Object:

The state data for the active button state, so that subclasses can use the value picked by this function without needing to calculate it themselves.

destroy

()
public

Defined in destroy:738

Destroys the button.

setText

(
  • text
)

Defined in setText:432

Sets the text of the label. This does nothing if the button was not initialized with a label.

Parameters:

  • text String

    The text to set the label to.

_currentLabelStyle

Object private

The current style for the label, to avoid setting this if it is unchanged.

_height

Number private

Defined in _height:200

The height of the button art, independent of the scaling of the button itself.

_offset

PIXI.Point private

Defined in _offset:185

An offset to button positioning, generally used to adjust for a highlight around the button.

_stateData

Object private

Defined in _stateData:169

A dictionary of state graphic data, keyed by state name. Each object contains the sourceRect (src) and optionally 'trim', another Rectangle. Additionally, each object will contain a 'label' object if the button has a text label.

_stateFlags

Object private

Defined in _stateFlags:153

A dictionary of state booleans, keyed by state name.

_statePriority

Array private

Defined in _statePriority:160

An array of state names (Strings), in their order of priority. The standard order previously was ["highlighted", "disabled", "down", "over", "selected", "up"].

_width

Number private

Defined in _width:193

The width of the button art, independent of the scaling of the button itself.

back

PIXI.Sprite

Defined in back:138

The sprite that is the body of the button.

BUTTON_OUT

String static

Defined in BUTTON_OUT:364

An event for when the button is moused out (while enabled).

BUTTON_OVER

String static

Defined in BUTTON_OVER:357

An event for when the button is moused over (while enabled).

BUTTON_PRESS

String static

Defined in BUTTON_PRESS:350

An event for when the button is pressed (while enabled).

enabled

Boolean

Defined in enabled:489

Whether or not the button is enabled.

Default: true

label

PIXI.Text | PIXI.BitmapText

Defined in label:145

The text field of the button. The label is centered by both width and height on the button.

useBoundsForSize

Boolean

Determines if width and height will calculate bounds of all children using getLocalBounds(), or only use the internal _width or _height. This should really only be set once, when the display object is initialized. Note that without this property, the default would be to use getLocalBounds();

Default: true