Sprite

The sprite component contains all of the necessary properities for the sprite of an entity. A spirte has a width, height, layer, start_x, start_y, texture_name and UV values.

Properties:

PropertyTypeFunctionality
widthfloatwidth of the sprite in pixels
heightfloatheight of the sprite in pixels
layerintthe layer of the sprite determines when it gets rendered. A lower layer will be rendered first.
start_xintdetermines the start x position for use in a texture atlas. If it is a single texture use 0.
start_yintdetermines the start y position for use in a texture atlas. If it is a single texture use 0.
bHiddenboolused to hide the texture when we don't want it to be seen.
texture_namestringthe name of the sprite to use. The name MUST exist in the Asset Manager prior to use.
colorColorThe color of the sprite. Defaults to white or Color(255, 255, 255, 255).

Functions:

FunctionDescription
generate_uvs()This function will take the width, height of the actual texture, and the start positions to populate the UV values for the texture atlas. UV values are u, v, uv_width, uv_height.

Use Example:

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

-- Add a new sprite component
local sprite = entity:add_component(
	Sprite(
		"hero_sprite",	-- texture_name
		32,		-- width 
		32,		-- height
		0, 		-- start_x
		0,		-- start_y
		2		-- layer
	)
)

-- After the sprite is created, you have to generate the uvs
sprite:generate_uvs()