Animation

The animation component is used to animate the sprite. It assumes that the sprite is part of a texture atlas and will adjust the current uv values based on the current frame.

Properties:

PropertyTypeFunctionality
numFramesintThe number of frames in the current animation.
frameRateintThe speed of the animation. How fast the frames change per second.
frameOffsetintThe offset from the start position. If the offset is not used, a start position of 0 is assumed.
currentFrameintThe frame that the animation is currently on.
startTimeintThe start time defaults to the current ticks upon creation. Used in the frame calculations.
bVerticalboolDetermines the direction of the animation scroll. True = vertically, False = horizontally.
bLoopedboolIf the animation is looped, it will reset the current frame to 0 once it reaches num_frames. If not looped, the user must call the reset() function to reset the animation.

Functions:

FunctionDescription
resetResets the current frame back to zero and sets the start_time to the current running ticks.

Use Example:

-- Create a new entity
local entity = Entity("tag", "group")

-- Add a new animation component
local animation = entity:add_component(
	Animation(
		4,		-- Number of frames 
		15,		-- Frame Rate
		0,		-- Frame Offset
		false,	-- bVertical == false == horizontal scroll
		true	-- Looped
	)
)