A simple button class that calls a function when touched.

Static variables

@:value(new Map())staticbuttonsTouchID:Map<Int, FunkinButton> = new Map()

A map that's storing every active touch's ID that's pressing a button.

Constructor

@:value({ y : 0, x : 0 })new(x:Float = 0, y:Float = 0)

Creates a new FunkinButton object.

Parameters:

x

The x position of the button.

y

The y position of the button.

Variables

read onlycurrentTouch:Null<FlxTouch>

The touch instance that pressed this button.

@:value([])deadZones:Array<FunkinSprite> = []

An array of objects that blocks your input.

@:value(false)ignoreDownHandler:Bool = false

Whether the button should skip calling onDownHandler() on touch.pressed.

read onlyjustPressed:Bool

Whether the button was just pressed.

read onlyjustReleased:Bool

Whether the button was just released.

@:value(true)limitToBounds:Bool = true

Whether the button should be released if you swiped over somwhere else.

@:value(new FlxSignal())read onlyonDown:FlxSignal = new FlxSignal()

The callback function to call when the button is pressed down.

@:value(new FlxSignal())read onlyonOut:FlxSignal = new FlxSignal()

The callback function to call when the button is no longer hovered over.

@:value(new FlxSignal())read onlyonUp:FlxSignal = new FlxSignal()

The callback function to call when the button is released.

@:value(null)polygon:Null<Array<Float>> = null

The vertices of the polygon defining the button's hitbox. The array should contain points in the format: [x1, y1, x2, y2, ...]. If the array is empty, the polygon is ignored, and the default hitbox is used.

read onlypressed:Bool

Whether the button is currently pressed.

@:value(0)radius:Float = 0

A radius for circular buttons. If this radius is larger than 0 then the overlap check will look if the touch point is inside this raius.

read onlyreleased:Bool

Whether the button is currently released.

Methods

destroy():Void

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

update(elapsed:Float):Void

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

Inherited Variables

Inherited Methods

Defined by FunkinSprite

clone():FunkinSprite

Ensure scale is applied when cloning a sprite.R The default clone() method acts kinda weird TBH.

Returns:

A clone of this sprite.

getCurrentAnimation():String

Gets the current animation ID.

getDefaultAtlasSettings():AtlasSpriteSettings

Gets the default settings for a texture atlas sprite.

Returns:

The default settings for a texture atlas sprite.

getDefaultSymbol():String

Returns the default symbol in the atlas.

getFirstElement(symbol:String):Null<Element>

Returns the first element of a symbol in the atlas.

Parameters:

symbol

The symbol to get elements from.

Returns:

The first element of the symbol. WARNING: Can be null.

getFrameLabel(name:String):Null<Frame>

Gets a frame label by its name.

Parameters:

name

The name of the frame label to retrieve.

Returns:

The frame label, or null if it doesn't exist.

getFrameLabelList():Array<String>

Gets a list of frame labels from the default timeline.

getFramesWithKeyword(keyword:String):Array<Frame>

Gets every frame on every symbol that starts with the given keyword.

Parameters:

keyword

The keyword to search for.

Returns:

An array of frames.

getSymbolElements(symbol:String):Array<Element>

Returns the elements of a symbol in the atlas.

Parameters:

symbol

The symbol to get elements from.

hasAnimation(id:String):Bool

Whether or not this sprite has an animation with the given ID.

Parameters:

id

The ID of the animation to check.

isAnimationDynamic(id:String):Bool

Parameters:

id

The animation ID to check.

Returns:

Whether the animation is dynamic (has multiple frames). false for static, one-frame animations.

isAnimationFinished():Bool

Whether or not the current animation is finished.

listAnimations():Array<String>

Returns:

A list of all the animations this sprite has available.

@:value({ cache : true })loadBitmapData(input:BitmapData, cache:Bool = true):FunkinSprite

Apply an OpenFL BitmapData to this sprite.

Parameters:

input

The OpenFL BitmapData to apply

Returns:

This sprite, for chaining

loadPacker(key:String):FunkinSprite

Load an animated texture (Packer atlas spritesheet) as the sprite's texture.

Parameters:

key

The key of the texture to load.

Returns:

This sprite, for chaining.

loadSparrow(key:String):FunkinSprite

Load an animated texture (Sparrow atlas spritesheet) as the sprite's texture.

Parameters:

key

The key of the texture to load.

Returns:

This sprite, for chaining.

loadTexture(key:String):FunkinSprite

Load a static image as the sprite's texture.

Parameters:

key

The key of the texture to load.

Returns:

This sprite, for chaining.

@:value({ fade : false })loadTextureAsync(key:String, fade:Bool = false):Void

loadTextureAtlas(key:Null<String>, ?assetLibrary:String, ?settings:Null<AtlasSpriteSettings>):FunkinSprite

Loads an Adobe Animate texture atlas as the sprite's texture.

Parameters:

key

The key of the texture to load.

settings

Additional settings for loading the atlas.

Returns:

This sprite, for chaining.

loadTextureBase(input:TextureBase):Null<FunkinSprite>

Apply an OpenFL TextureBase to this sprite.

Parameters:

input

The OpenFL TextureBase to apply

Returns:

This sprite, for chaining

@:value({ color : FlxColor.WHITE })makeSolidColor(width:Int, height:Int, color:FlxColor = FlxColor.WHITE):FunkinSprite

Acts similarly to makeGraphic, but with improved memory usage, at the expense of not being able to paint onto the resulting sprite.

Parameters:

width

The target width of the sprite.

height

The target height of the sprite.

color

The color to fill the sprite with.

Returns:

This sprite, for chaining.

@:value({ adjustScale : true })replaceSymbolGraphic(symbol:String, ?graphic:FlxGraphicAsset, adjustScale:Bool = true):Void

Replaces the graphic of a symbol in the atlas.

Parameters:

symbol

The symbol to replace.

graphic

The new graphic to use.

adjustScale

Whether to adjust the scale of new frame to match the old one.

@:value({ scaleEverything : false, positionOffset : 0 })scaleElement(element:Element, scale:Float, positionOffset:Float = 0, scaleEverything:Bool = false):Void

Scales an element by a certain multiplier.

Parameters:

element

The element to scale.

scale

The scale multiplier.

positionOffset

The offset to apply to tx and ty after scaling. (Or in other words, the position of the element.)