This is a rework of the health icon with the following changes: - The health icon now owns its own state logic. It queries health and updates the sprite itself, rather than relying on PlayState to command it. - The health icon now supports animations.

 - The health icon will now search for a SparrowV2 (XML) spritesheet, and use that for rendering if it can.
 - If it can't find a spritesheet, it will the old format; a two-frame 300x150 image.
  • If the spritesheet is found, the health icon will attempt to load and use the following animations as appropriate:

     - `idle`, `winning`, `losing`, `toWinning`, `fromWinning`, `toLosing`, `fromLosing`
    
  • The health icon is now easier to control via scripts. - Set autoUpdate to false to prevent the health icon from changing its own animations.
  • Once autoUpdate is false, you can manually call playAnimation() to play a specific animation. - i.e. PlayState.instance.iconP1.playAnimation("losing")
  • Scripts can also utilize all functionality that a normal FlxSprite would have access to, such as adding supplimental animations. - i.e. PlayState.instance.iconP1.animation.addByPrefix("jumpscare", "jumpscare", 24, false);

Static variables

@:value(150)staticfinalread onlyHEALTH_ICON_SIZE:Int = 150

The size of a non-pixel icon when using the legacy format. Remember, modern icons can be any size.

Constructor

@:value({ playerId : 0 })new(char:Null<String>, playerId:Int = 0)

Variables

@:value(true)autoUpdate:Bool = true

Whether this health icon should automatically update its state based on the character's health. Note that turning this off means you have to manually do the following: - Boping the icon on the beat. - Switching between winning/losing/idle animations. - Repositioning the icon as health changes.

@:value(0.0)bopAngle:Float = 0.0

The amount, in degrees, to rotate the icon by when boping. ERIC NOTE: I experimented with this a bit but ended up turning it off, but why not leave it in for the script kiddies?

@:value(Constants.STEPS_PER_BEAT)bopEvery:Int = Constants.STEPS_PER_BEAT

Apply the "bop" animation once every X steps. Defaults to once per beat.

@:value(null)bopTween:Null<FlxTween> = null

Tween, that makes icon bop.

@:value(Constants.DEFAULT_HEALTH_ICON)characterId:String = Constants.DEFAULT_HEALTH_ICON

The character this icon is representing. Setting this variable will automatically update the graphic.

@:value(FlxPoint.get())iconOffset:FlxPoint = FlxPoint.get()

@:value(false)isPixel:Bool = false

Whether the sprite is pixel art or not.

size:FlxPoint

Since the scale of the sprite dynamically changes over time, this value allows you to set a relative scale for the icon.

Methods

configure(data:Null<HealthIconData>):Void

Use the provided CharacterHealthIconData to configure this health icon's appearance.

Parameters:

data

The data to use to configure this health icon.

onStepHit(curStep:Int):Void

Called on every step.

Parameters:

curStep

The current step number.

@:value({ restart : false, fallback : null })playAnimation(name:String, ?fallback:String, restart:Bool = false):Void

Plays the animation with the given name.

Parameters:

name

The name of the animation to play.

fallback

The fallback animation to play if the given animation is not found.

restart

Whether to forcibly restart the animation if it is already playing.

toggleOldIcon():Void

Easter egg; press 9 in the PlayState to use the old player icon.

update(elapsed:Float):Void

Called by Flixel every frame. Includes logic to manage the currently playing animation.

updatePosition():Void

Update the position (and status) of the health icon.

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.)