diff --git a/inc/sprite/sprite.manager.lua b/inc/sprite/sprite.manager.lua index 9754b4f..ad85dce 100644 --- a/inc/sprite/sprite.manager.lua +++ b/inc/sprite/sprite.manager.lua @@ -50,6 +50,29 @@ function Sprite.register(sprite_data) _sprites[sprite_data.id] = sprite_data end +--- Generates a sprites table for a rectangular composite sprite. +--- @within Sprite +--- @param width number The number of sprites wide.
+--- @param height number The number of sprites tall.
+--- @param starting_s number The sprite index of the top-left tile.
+--- @param x_base number The base x-offset for the leftmost column.
+--- @param y_base number The base y-offset for the topmost row.
+--- @param x_step number The x-offset increment per column.
+--- @param y_step number The y-offset increment per row.
+--- @return table The sprites table array. +function Sprite.generate_table(width, height, starting_s, x_base, y_base, x_step, y_step) + local sprites = {} + for row = 0, height - 1 do + for col = 0, width - 1 do + local s = starting_s + row * 16 + col + local x_offset = x_base + col * x_step + local y_offset = y_base + row * y_step + table.insert(sprites, { s = s, x_offset = x_offset, y_offset = y_offset }) + end + end + return sprites +end + --- Schedules a sprite for drawing. --- @within Sprite --- @param id string The unique identifier of the sprite.