FlxTypedButton
| Kind | class |
| Package | mobile.flixel |
| Full name | mobile.flixel.FlxTypedButton |
| Source | source/mobile/flixel/FlxButton.hx |
| Extends | FlxSprite |
| Implements | IFlxInput |
| Metadata | @:generic |
Known subclasses: FlxButton
Public fields
| Name | Type | Static | Default | Notes |
|---|---|---|---|---|
label | T | no | — | property (default, set) · The label that appears on the button. Can be any FlxSprite. |
labelOffsets | Array<FlxPoint> | no | [FlxPoint.get(), FlxPoint.get(), FlxPoint.get(0, 1)] | What offsets the label should have for each status. |
labelAlphas | Array<Float> | no | [0.8, 1.0, 0.5] | What alpha value the label should have for each status. Default is [0.8, 1.0, 0.5]. Multiplied with the button's alpha. |
statusAnimations | Array<String> | no | ['normal', 'highlight', 'pressed'] | What animation should be played for each status. Default is ['normal', 'highlight', 'pressed']. |
allowSwiping | Bool | no | true | Whether you can press the button simply by releasing the touch button over it (default). If false, the input has to be pressed while hovering over the button. |
multiTouch | Bool | no | false | Whether the button can use multiple fingers on it. |
maxInputMovement | Float | no | Math.POSITIVE_INFINITY | Maximum distance a pointer can move to still trigger event handlers. If it moves beyond this limit, onOut is triggered. Defaults to Math.POSITIVE_INFINITY (i.e. no limit). |
status | Int | no | — | property (default, set) · Shows the current state of the button, either FlxButton.NORMAL, FlxButton.HIGHLIGHT or FlxButton.PRESSED. |
onUp | FlxButtonEvent | no | — | property (default, null) · The properties of this button's onUp event (callback function, sound). |
onDown | FlxButtonEvent | no | — | property (default, null) · The properties of this button's onDown event (callback function, sound). |
onOver | FlxButtonEvent | no | — | property (default, null) · The properties of this button's onOver event (callback function, sound). |
onOut | FlxButtonEvent | no | — | property (default, null) · The properties of this button's onOut event (callback function, sound). |
justReleased | Bool | no | — | property (get, never) |
released | Bool | no | — | property (get, never) |
pressed | Bool | no | — | property (get, never) |
justPressed | Bool | no | — | property (get, never) |
Public methods
new (constructor)
function new(X:Float = 0, Y:Float = 0, ?OnClick:Void->Void):Void
Creates a new FlxTypedButton object with a gray background.
@param X The x position of the button. @param Y The y position of the button. @param OnClick The function to call whenever the button is clicked.
| Parameter | Type | Default |
|---|---|---|
X (optional) | Float | 0 |
Y (optional) | Float | 0 |
OnClick (optional) | Void->Void | — |
graphicLoaded
override function graphicLoaded():Void
destroy
override function destroy():Void
Called by the game state when state is changed (if this object belongs to the state)
update
override function update(elapsed:Float):Void
Called by the game loop automatically, handles touch over and click detection.
| Parameter | Type | Default |
|---|---|---|
elapsed | Float | — |
draw
override function draw():Void
Just draws the button graphic and text label to the screen.
drawDebug
override function drawDebug():Void
Only compiled when #if FLX_DEBUG.
Helper function to draw the debug graphic for the label as well.
stampOnAtlas
function stampOnAtlas(atlas:FlxAtlas):Bool
Stamps button's graphic and label onto specified atlas object and loads graphic from this atlas. This method assumes that you're using whole image for button's graphic and image has no spaces between frames. And it assumes that label is a single frame sprite.
@param atlas Atlas to stamp graphic to. @return Whether the button's graphic and label's graphic were stamped on the atlas successfully.
| Parameter | Type | Default |
|---|---|---|
atlas | FlxAtlas | — |
Internals
Private / internal members
| Field | Type | Static |
|---|---|---|
_spriteLabel | FlxSprite | no |
input | FlxInput<Int> | no |
currentInput | IFlxInput | no |
lastStatus | — | no |
| Method |
|---|
function loadDefaultGraphic():Void |
function setupAnimation(animationName:String, frameIndex:Int):Void |
function updateStatusAnimation():Void |
function updateButton():Void |
function updateMultiTouch():Void |
function checkTouchOverlap():Bool |
function checkInput(pointer:FlxPointer, input:IFlxInput, justPressedPosition:FlxPoint, camera:FlxCamera):Bool |
function updateStatus(input:IFlxInput):Void |
function updateLabelPosition() |
function updateLabelAlpha() |
function onUpHandler():Void |
function onDownHandler():Void |
function onOverHandler():Void |
function onOutHandler():Void |
function set_label(Value:T):T |
function set_status(Value:Int):Int |
override function set_alpha(Value:Float):Float |
override function set_x(Value:Float):Float |
override function set_y(Value:Float):Float |
inline function get_justReleased():Bool |
inline function get_released():Bool |
inline function get_pressed():Bool |
inline function get_justPressed():Bool |