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.
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]
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
[label=null]
Object
optional
[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
[label=null]
Object
optional
[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
[label=null]
Object
optional
[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
[label=null]
Object
optional
[<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
[label=null]
Object
optional
[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
Adds a property to the button. Setting the property sets the value in _stateFlags and calls _updateState().
propertyName
String
The property name to add to the button.
_onUp
The callback for when the button for when the mouse/touch is released on the button
_onUpOutside
The callback for when the mouse/touch is released outside the button when the button was held down.
_updateState
Updates back based on the current button state.
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.
setText
text
Sets the text of the label. This does nothing if the button was not initialized with a label.
text
String
The text to set the label to.
_currentLabelStyle
The current style for the label, to avoid setting this if it is unchanged.
_height
The height of the button art, independent of the scaling of the button itself.
_offset
An offset to button positioning, generally used to adjust for a highlight around the button.
_stateData
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.
_statePriority
An array of state names (Strings), in their order of priority. The standard order previously was ["highlighted", "disabled", "down", "over", "selected", "up"].
label
The text field of the button. The label is centered by both width and height on the button.
useBoundsForSize
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