jubilant-funicular
Public Member Functions | Public Attributes | List of all members
nta::SpriteSheet Struct Reference

Multiple sprites (each the same size) in one texture. More...

#include <Animation2D.h>

Collaboration diagram for nta::SpriteSheet:
Collaboration graph
[legend]

Public Member Functions

 SpriteSheet (const GLTexture &tex, crivec2 dims)
 
 SpriteSheet (ContextData &context, crstring file_path, crivec2 dims)
 
 SpriteSheet (ContextData &context, crstring file_path, int num_cols)
 
std::size_t num_sprites () const
 Returns the number of sprites in this sheet.
 
glm::vec2 sprite_dims () const
 
std::size_t sprite_area () const
 
glm::vec4 get_uv (std::size_t index) const
 
glm::vec4 get_flipped_uv (std::size_t index) const
 Like get_uv except it flips the sprite horizontally.
 
glm::vec2 get_frame_dims () const
 Returns the dimensions of one sprite in this sheet.
 
void read_sprite_pixels (GLubyte *pixels, std::size_t index) const
 

Public Attributes

GLTexture tex
 The texture holding all the sprites.
 
union {
glm::ivec2 dims
 
   struct {
int num_rows
 
int num_cols
 
   } 
 
}; 
 The dimensions of the sheet (rows x cols)
 

Detailed Description

Multiple sprites (each the same size) in one texture.

Definition at line 8 of file Animation2D.h.

Member Function Documentation

◆ get_uv()

glm::vec4 nta::SpriteSheet::get_uv ( std::size_t  index) const
inline

Gets UV-coordinates of specific sprite in the sheet

The topleft sprite is index 0 and indices increase moving to the right

Definition at line 33 of file Animation2D.h.

Referenced by get_flipped_uv().

◆ read_sprite_pixels()

void nta::SpriteSheet::read_sprite_pixels ( GLubyte *  pixels,
std::size_t  index 
) const

Reads pixels of one sprite into buffer specified by pixels

pixels will contain RGB values, so should be size >= sprite_area()*3

Definition at line 11 of file Animation2D.cpp.


The documentation for this struct was generated from the following files: