Public Types | Public Member Functions | Private Attributes | List of all members
nom::SpriteSheet Class Reference

Specialized class container for the creation of sprite sheets via RFC 4627 JSON-compliant file input. More...

#include <SpriteSheet.hpp>

Public Types

typedef std::shared_ptr
< SpriteSheet > 
SharedPtr
 

Public Member Functions

 SpriteSheet (void)
 
 ~SpriteSheet (void)
 Destructor.
 
 SpriteSheet (const std::string &filename)
 Construct a sprite sheet from an existing sprite sheet file.
 
 SpriteSheet (const std::string &filename, int32 sheet_width, int32 sheet_height, int32 sprite_width, int32 sprite_height, int32 spacing, int32 padding, int32 num_sprites)
 
SpriteSheet::SharedPtr clone (void) const
 Make a duplicate of this object's instance.
 
const Coords & dimensions (int32 index) const
 Get the calculations made for a particular ID number.
 
int32 frames (void) const
 Obtain the number of frames this object contains.
 
const std::string & sheet_filename (void) const
 
bool save (const std::string &filename)
 
bool load (const std::string &filename)
 
void dump (void) const
 Dump the state of this object instance.
 

Private Attributes

std::vector< Coords > sheet
 Our sprite sheet values container.
 
std::string sheet_filename_
 Source filename used is saved with the output (meta-data)
 
int32 sheet_sprites
 
int32 sheet_spacing
 Source spacing used is saved with the output (meta-data)
 
int32 sheet_padding
 Source padding used is saved with the output (meta-data)
 
int32 sheet_width
 Source sheet_width used is saved with the output (meta-data)
 
int32 sheet_height
 Source sheet_height used is saved with the output (meta-data)
 

Detailed Description

Specialized class container for the creation of sprite sheets via RFC 4627 JSON-compliant file input.

       [DESCRIPTION STUB]
*
* Example of 4X4 Sheet
* ________________
* | 0 | 1 | 2 | 3 |
* |===============|
* | 0 | 1 | 2 | 3 |
* |===============|
* | 0 | 1 | 2 | 3 |
* |===============|
* | 0 | 1 | 2 | 3 |
* |---------------|
*
*

Usage example:

*
* #include <nomlib/graphics/SpriteSheet.hpp>
* #include <nomlib/graphics/Sprite.hpp>
*
* nom::SpriteSheet card_faces_sheet ( "faces.png", 256, 262, 64, 64, 0, 1, 16 );
* card_faces_sheet.save( "faces.json" );
*
* nom::Sprite card_face = nom::Sprite ( card_faces_sheet );
*
* // ...or!
*
* nom::Sprite card_face ( nom::SpriteSheet ( card_faces_sheet ( "faces.json" ) ) );
*
*
*
* REFERENCES
*
* 1. http://www.dreamincode.net/forums/topic/179429-sdl-sprite-sheet/
*
Todo:
Re-design the JSON layout used, perhaps with something like: { "metadata": { }, "<filename>": { "<ID>": { } } }
Todo:
Re-consider our sheet vector's data type (nom::Coords); we should ideally be loading the object's ID into this vector
Todo:
Create structs for our instance vars
Todo:
Buffer the file meta-data like we do the other JSON objects inside load method

Definition at line 62 of file SpriteSheet.hpp.

Constructor & Destructor Documentation

nom::SpriteSheet::SpriteSheet ( void  )

Default construct for initializing instance variables to their respective defaults.

Definition at line 37 of file SpriteSheet.cpp.

nom::SpriteSheet::SpriteSheet ( const std::string &  filename,
int32  sheet_width,
int32  sheet_height,
int32  sprite_width,
int32  sprite_height,
int32  spacing,
int32  padding,
int32  num_sprites 
)

Construct a sprite sheet from a given list of arguments. The total tile count is used if the num_sprites argument is not initialized.

The filename specified is used only as meta-data.

Padding is applied on all four sides. Spacing is applied between each tile.

Todo:

Re-order these arguments to match the order of instance variables

Add additional sanity-check asserts for spacing, padding and so on

Definition at line 56 of file SpriteSheet.cpp.

Member Function Documentation

bool nom::SpriteSheet::load ( const std::string &  filename)

Load saved sprite sheet data from a file encoded as an RFC 4627 compliant JSON object.

Definition at line 220 of file SpriteSheet.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool nom::SpriteSheet::save ( const std::string &  filename)

Save the current sprite sheet data calculations to a file as a series of RFC 4627 compliant JSON objects.

Definition at line 182 of file SpriteSheet.cpp.

Here is the call graph for this function:

Member Data Documentation

int32 nom::SpriteSheet::sheet_sprites
private

Source number of sprites specified; this is saved with the resulting output as meta-data

Definition at line 126 of file SpriteSheet.hpp.


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