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