new Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)
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.
A different texture/frame and activation sound can be specified for any of the states.
Frames can be specified as either an integer (the frame ID) or a string (the frame name); the same values that can be used with a Sprite constructor.
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 (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 | integer | <optional> | The frame / frameName when the button is in the Over state. | |
outFrame | string | integer | <optional> | The frame / frameName when the button is in the Out state. | |
downFrame | string | integer | <optional> | The frame / frameName when the button is in the Down state. | |
upFrame | string | integer | <optional> | The frame / frameName when the button is in the Up state. |
- Source code: gameobjects/Button.js (Line 35)
Please login to continue.