Skip to main content

FlxTypedButton

Kindclass
Packagemobile.flixel
Full namemobile.flixel.FlxTypedButton
Sourcesource/mobile/flixel/FlxButton.hx
ExtendsFlxSprite
ImplementsIFlxInput
Metadata@:generic

Known subclasses: FlxButton

Public fields​

NameTypeStaticDefaultNotes
labelTno—property (default, set) · The label that appears on the button. Can be any FlxSprite.
labelOffsetsArray<FlxPoint>no[FlxPoint.get(), FlxPoint.get(), FlxPoint.get(0, 1)]What offsets the label should have for each status.
labelAlphasArray<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.
statusAnimationsArray<String>no['normal', 'highlight', 'pressed']What animation should be played for each status. Default is ['normal', 'highlight', 'pressed'].
allowSwipingBoolnotrueWhether 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.
multiTouchBoolnofalseWhether the button can use multiple fingers on it.
maxInputMovementFloatnoMath.POSITIVE_INFINITYMaximum 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).
statusIntno—property (default, set) · Shows the current state of the button, either FlxButton.NORMAL, FlxButton.HIGHLIGHT or FlxButton.PRESSED.
onUpFlxButtonEventno—property (default, null) · The properties of this button's onUp event (callback function, sound).
onDownFlxButtonEventno—property (default, null) · The properties of this button's onDown event (callback function, sound).
onOverFlxButtonEventno—property (default, null) · The properties of this button's onOver event (callback function, sound).
onOutFlxButtonEventno—property (default, null) · The properties of this button's onOut event (callback function, sound).
justReleasedBoolno—property (get, never)
releasedBoolno—property (get, never)
pressedBoolno—property (get, never)
justPressedBoolno—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.

ParameterTypeDefault
X (optional)Float0
Y (optional)Float0
OnClick (optional)Void->Void—

View source

graphicLoaded​

override function graphicLoaded():Void

View source

destroy​

override function destroy():Void

Called by the game state when state is changed (if this object belongs to the state)

View source

update​

override function update(elapsed:Float):Void

Called by the game loop automatically, handles touch over and click detection.

ParameterTypeDefault
elapsedFloat—

View source

draw​

override function draw():Void

Just draws the button graphic and text label to the screen.

View source

drawDebug​

override function drawDebug():Void

Only compiled when #if FLX_DEBUG.

Helper function to draw the debug graphic for the label as well.

View source

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.

ParameterTypeDefault
atlasFlxAtlas—

View source

Internals​

Private / internal members
FieldTypeStatic
_spriteLabelFlxSpriteno
inputFlxInput<Int>no
currentInputIFlxInputno
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