Create a new ButtonComponent instance.
The ComponentSystem that created this component.
The entity that this component is attached to.
The Entity that this Component is attached to.
The ComponentSystem used to create this Component.
Gets the button's active state.
Sets the button's active state. If set to false, the button will be visible but will not respond to hover or touch interactions. Defaults to true.
Gets the enabled state of the component.
Sets the enabled state of the component.
Gets the duration to be used when fading between tints, in milliseconds.
Sets the duration to be used when fading between tints, in milliseconds. Defaults to 0.
Gets the padding to be used in hit-test calculations.
Sets the padding to be used in hit-test calculations. Can be used to expand the bounding box
so that the button is easier to tap. Defaults to [0, 0, 0, 0]
.
Gets the frame to be used from the hover sprite.
Sets the frame to be used from the hover sprite.
Gets the entity to be used as the button background.
Sets the entity to be used as the button background. The entity must have an ElementComponent configured as an image element.
Gets the frame to be used from the inactive sprite.
Sets the frame to be used from the inactive sprite.
Gets the tint color to be used on the button image when the button is not interactive.
Sets the tint color to be used on the button image when the button is not interactive.
Defaults to [0.25, 0.25, 0.25]
.
Gets the frame to be used from the pressed sprite.
Sets the frame to be used from the pressed sprite.
Gets the button transition mode.
Sets the button transition mode. This controls how the button responds when the user hovers over it/presses it. Can be:
Defaults to BUTTON_TRANSITION_MODE_TINT.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Static
EVENT_Fired when the mouse is pressed and released on the component or when a touch starts and ends on the component. The handler is passed a ElementMouseEvent or ElementTouchEvent.
Static
EVENT_Fired when the button changes state to be not hovered.
Static
EVENT_Fired when the button changes state to be hovered.
Static
EVENT_Fired when the mouse is pressed while the cursor is on the component. The handler is passed a ElementMouseEvent.
Static
EVENT_Fired when the mouse cursor enters the component. The handler is passed a ElementMouseEvent.
Static
EVENT_Fired when the mouse cursor leaves the component. The handler is passed a ElementMouseEvent.
Static
EVENT_Fired when the mouse is released while the cursor is on the component. The handler is passed a ElementMouseEvent.
Static
EVENT_Fired when the button changes state to be not pressed.
Static
EVENT_Fired when the button changes state to be pressed.
Static
EVENT_Fired when a xr select ends on the component. The handler is passed a ElementSelectEvent.
Static
EVENT_Fired when a xr select now hovering over the component. The handler is passed a ElementSelectEvent.
Static
EVENT_Fired when a xr select not hovering over the component. The handler is passed a ElementSelectEvent.
Static
EVENT_Fired when a xr select starts on the component. The handler is passed a ElementSelectEvent.
Static
EVENT_Fired when a touch is canceled on the component. The handler is passed a ElementTouchEvent.
Static
EVENT_Fired when a touch ends on the component. The handler is passed a ElementTouchEvent.
Static
EVENT_Fired when a touch leaves the component. The handler is passed a ElementTouchEvent.
Static
EVENT_Fired when a touch starts on the component. The handler is passed a ElementTouchEvent.
A ButtonComponent enables a group of entities to behave like a button, with different visual states for hover and press interactions.