Skip to content

Lua API: Sprites

nebulazorua edited this page Dec 10, 2021 · 1 revision

Sprites allow you to interface with HaxeFlixel's "FlxSprite" class. Many classes, such as Receptor and Character, inherit from this.

Properties

Property Value Type Description
spriteName string Used internally. Read-only.
x number The sprite's x position. Equivilant to FlxSprite.y
y number The sprite's y position. Equivilant to FlxSprite.x
alpha number The sprite's transparency, where 1 is fully opaque and 0 is fully transparent. Equivilant to FlxSprite.alpha
angle number The sprite's angle in degrees. Equivilant to FlxSprite.angle
width number The sprite's hitbox's width. Equivilant to FlxSprite.width
height number The sprite's hitbox's height. Equivilant to FlxSprite.height
scrollFactorX number The sprite's horizontal paralaxing. Equivilant to FlxSprite.scrollFactor.x
scrollFactorY number The sprite's vertical paralaxing. Equivilant to FlxSprite.scrollFactor.y
scaleX number The sprite's horizontal scale. Equivilant to FlxSprite.scale.x
scaleY number The sprite's vertical scale. Equivilant to FlxSprite.scale.y
antialiasing bool Whether the sprite should have antialiasing or not. Equivilant to FlxSprite.antialiasing
active bool Whether the sprite should call the associated FlxSprite's update function in HaxeFlixel. Equivilant to FlxSprite.active
visible bool The sprite's visibility. Equivilant to FlxSprite.visible
flipX bool Flips the sprite horizontally. Equivilant to FlxSprite.flipX
flipY bool Flips the sprite vertically. Equivilant to FlxSprite.flipY

Methods

void setScale(number scale)

Sets the scale of the sprite.

void tween(Dictionary properties, number time, string easingStyle)

Tweens the properties to the specified value over the specified length. easingStyle names can be found at https://api.haxeflixel.com/flixel/tweens/FlxEase.html

Note that the property names must be FlxSprite property names, not Sprite property names ("scrollFactor.x" instead of "scrollFactorX")

number, number screenCenter(string axes)

Centers the screen on the specified axes.

Valid axes are "X", "Y" and "XY"

Returns the sprite's new X and Y position.

Any getProperty(string property)

Returns the associated FlxSprite's property's value.

void setFrames(string path)

Sets the associated FlxSprite's frames property to the Sparrow Atlas at the path.

Note that the path is localized at the song's folder!

void addAnimByPrefix(string name, string prefix, number frameRate=24, bool looped=true, bool flipX=false, bool flipY=false)

Equivilant to FlxSprite.animation.addByPrefix. Make sure you use setFrames before using this!

void addAnimByIndices(string name, string prefix, Array<number> indices, number frameRate=24, bool looped=true, bool flipX=false, bool flipY=false)

Equivilant to FlxSprite.animation.addByIndices. Make sure you use setFrames before using this!

void addAnim(string name, Array<number> frames, number frameRate=24, bool looped=true, bool flipX=false, bool flipY=false)

Equivilant to FlxSprite.animation.add.

void loadGraphic(string path, bool animated=false, number width=0, numberheight=0)

Equivilant to FlxSprite.loadGraphic

Note that the path is localized to the song's folder!

void changeAnimFramerate(string name, number newFramerate)

Changes the animation's framerate to newFramerate.

bool animExists(string name)

Returns if the animation is registered on the sprite

void playAnim(string name, bool force=false, bool reversed=false, number startFrame=0)

Plays an animation on the sprite. Equivilant to FlxSprite.animation.play