Module sprite

A drawable graphic with multiple frames determined by a sprite sheet.

Sprite extends BoundObject

Properties

current_animation (read only) The current SpriteAnimation that is playing.
direction A number representing the current direction the sprite is facing.

Class Methods

Sprite:new (file_name, cell_size, padding) Create a new Sprite from a sprite sheet.

Instance Methods

sprite:add_animation (animation, name) Adds a SpriteAnimation to Sprite with the given name.
sprite:get_animation (name) Find the SpriteAnimation with the given name
sprite:use_animation (name) Use the animation named name.


Properties

Properties. Significant fields on an instance.
current_animation
(read only) The current SpriteAnimation that is playing.
direction
A number representing the current direction the sprite is facing. Can be 0 (right) or 180 (left). A value of 180 will flip the sprite horizontally.

Default 0

Class Methods

Class Methods. Must be called on Class, with a capital leading character. e.g. Class:method("foo")
Sprite:new (file_name, cell_size, padding)
Create a new Sprite from a sprite sheet.

Parameters:

  • file_name string The file name of the sprite sheet image to load.
  • cell_size table An {x, y} vector representing the size of a single frame in pixels.
  • padding number The amount of padding between each cell in pixels.

Returns:

    Sprite

Instance Methods

Instance Methods. Must be called on an instance of Class. e.g. instance:method("foo")
sprite:add_animation (animation, name)
Adds a SpriteAnimation to Sprite with the given name.

Parameters:

  • animation SpriteAnimation The animation to add
  • name string The name for the animation.

Returns:

    nil
sprite:get_animation (name)
Find the SpriteAnimation with the given name

Parameters:

  • name string The name of the animation to retrieve.

Returns:

    SpriteAnimation
sprite:use_animation (name)
Use the animation named name. If that is already the current animation or the animation is not found, nothing happens.

Parameters:

  • name string The name of the animation to use.

Returns:

    nil
generated by LDoc 1.3.12