Sprites

namespace tnt
namespace doo

Variables

struct tnt::doo::sprites_sys sprites
struct sprite_comp
#include <Sprites.hpp>

A struct that handles an object’s sprite data.

Public Functions

sprite_comp(Window const &win, std::string_view filename) noexcept

Create a new sprite component from an image file.

Parameters
  • win: The window where the sprite will be drawed.

  • filename: The name of the image file to load.

sprite_comp(Window const &win, std::string_view filename, Rectangle const &rect) noexcept

Create a new sprite component from an image file.

Parameters
  • win: The window where the sprite will be drawed.

  • filename: The name of the image file to load.

  • rect: The area of the image you want to have on the sprite.

Public Members

SDL_Texture *tex
SDL_Rect crop

< The texture handle for the object.

Private Members

int w

< The area of the image represented on the sprite.

int h
struct sprites_sys
#include <Sprites.hpp>

A struct that handles the sprite data for all the objects.

Public Functions

void add_object(object const &id, sprite_comp const &sprite)

Add a new object to the sprites system.

Parameters
  • id: The id of the object to add to the sprites system.

  • sprite: The sprite component of the object.

void from_json(object const &id, Window const &win, nlohmann::json const &j)

Load the sprite data of the objects from a given json chunk.

Parameters
  • id: The id of the object to load from json.

  • win: The window where the loaded sprite component will be drawed.

  • j: The json chunk from where to load the sprite data of the objects.

void to_json(object const &id, nlohmann::json &j)

Store sprites data of a specific object to a json chunk.

Parameters
  • id: The id of the object to serialize to json.

  • j: The json chunk where the data will be saved.

void draw_imgui(object const &id, Window const &win) noexcept

Draw widgets on the given window to modify the datas of the system.

Parameters
  • id: The id of the active object.

  • win: The window where to draw the widgets.

Rectangle draw_area(object const &id) const noexcept

Get a tnt::Rectangle that contains the area where the object will be drawed.

Return

tnt::Rectangle

Parameters
  • id: The id of the object.

void target_cam(camera const &cam) noexcept

Draw all the following objects to the given camera. If passed tnt::doo::null, the objects will be drawed as if no camera was set.

Parameters
  • cam: The id of the target camera.

void Draw(object const &id, Window const &win) const noexcept

Draw object with the given id on the given window.

Parameters
  • id: The id of the object to draw.

  • win: The window where the object will be drawed.

void remove(object const &id) noexcept

Remove the desired object from the sprites system.

Parameters
  • id: The id of the object you want to remove.

void clear() noexcept

Remove all the objects from the sprites system.

Public Members

camera target = {null_v<camera>}
std::vector<SDL_Texture*> tex

< The camera where the objects will be drawed.

std::vector<SDL_Rect> clip

< The texture data of the objects.

sparse_set<object> active

< The cropped area from the image.