nomlib
Loading...
Searching...
No Matches
nom::SpriteBatch Class Reference

Extended sprite rendering using sprite sheets. More...

#include <SpriteBatch.hpp>

Inheritance diagram for nom::SpriteBatch:
[legend]

Public Types

typedef SpriteBatch self_type
typedef Sprite derived_class
Public Types inherited from nom::Sprite
typedef Sprite self_type
typedef Transformable derived_class
Public Types inherited from nom::Transformable
typedef Transformable self_type
Public Types inherited from nom::IDrawable
typedef IDrawable self_type
typedef self_type * raw_ptr
 A type definition for a C pointer – raw pointer – to an IDrawable object.
typedef std::unique_ptr< self_type > unique_ptr
 A type definition for a C++11 std::unique_ptr to an IDrawable object.
typedef std::shared_ptr< self_type > shared_ptr
 A type definition for a C++11 std::shared_ptr to an IDrawable object.
typedef const RenderWindow RenderTarget
Public Types inherited from nom::IObject
typedef IObject self_type
typedef IObjectraw_ptr

Public Member Functions

 SpriteBatch ()
virtual ~SpriteBatch ()
 Destructor.
virtual void set_sprite_sheet (const SpriteSheet &sheet)
 Use the sprite frames from an existing SpriteSheet object.
ObjectTypeInfo type () const override
 Re-implements the IObject::type method.
SpriteBatchclone () const
 Implements the required IDrawable::clone method.
virtual int32 frame () const
 Get the object's current sheet_id.
int32 frames () const
 Obtain the number of frames available.
void set_frame (int32 id)
 Set a new frame ID to render.
virtual void draw (IDrawable::RenderTarget &target) const override
 Render the sprite frame.
virtual void draw (RenderTarget &target, real64 angle) const override
 Render the sprite frame at an angle.
Public Member Functions inherited from nom::Sprite
bool init_with_color (const Color4i &color, const Size2i &dims)
 Construct a sprite from a dimension and color.
virtual void set_position (const Point2i &pos) override
 Re-implements Transformable::set_position.
virtual void set_size (const Size2i &dims) override
 Re-implements Transformable::set_size.
std::unique_ptr< Sprite > clone () const
 Implements the required IDrawable::clone method.
std::shared_ptr< Texturetexture () const
bool valid () const
Color4i color () const
 Get the texture color of the sprite.
BlendMode color_blend_mode () const
 Get the color blend mode of the sprite.
uint8 alpha () const
 Get the alpha value of the sprite.
bool set_texture (Texture &tex)
 Construct a sprite from an existing texture source.
bool set_texture (Texture *tex)
 Construct a sprite from an existing texture source.
bool set_texture (std::shared_ptr< Texture > &tex)
 Construct a sprite from an existing texture source.
bool set_alpha (uint8 opacity)
bool set_color (const Color4i &color)
bool set_color_blend_mode (BlendMode blend)
void release_texture ()
 Free the stored texture.
Public Member Functions inherited from nom::Transformable
 Transformable (const Point2i &pos, const Size2i &size)
 Transformable (const IntRect &bounds)
 Construct an object using a complete set of coordinates (bounds).
ObjectTypeInfo type () const override
 Re-implements the IObject::type method.
const Point2i & position (void) const
 Getter for stored positioning coordinates.
const Size2i & size (void) const
 Getter for stored size dimensions.
virtual void set_bounds (const IntRect &bounds)
 Set the complete bounds of the object – position (X, Y) and size (width and height) dimensions.
void set_position (int x, int y)
void set_size (int w, int h)
virtual void translate (const Point2i &pos)
Public Member Functions inherited from nom::IDrawable
 IDrawable (void)
 Do nothing at all default constructor.
virtual ~IDrawable (void)
 Do nothing at all destructor.
Public Member Functions inherited from nom::IObject
 IObject (void)
 Default constructor.
virtual ~IObject (void)
 Virtual destructor.
virtual bool is_type (const ObjectTypeInfo &rhs) const
 Compare this object type with another object's type.

Protected Attributes

IntRect offsets
 Source (input) coordinates – used for sprite sheet positioning.
SpriteSheet sprite_sheet
 Our attached sprite sheet object.
int32 sheet_id_
 The sheet's frame ID presently in use.
Protected Attributes inherited from nom::Sprite
std::shared_ptr< Texturetexture_
 The underlying texture for the sprite.

Private Member Functions

virtual void update () override
 Update the sprite for rendering with regard to positioning coordinates and target frame ID.

Additional Inherited Members

Static Public Member Functions inherited from nom::IObject
template<typename Base, typename Derived>
static bool is_a (const Derived object)
 Compare two objects to determine if a derived class inherits from a base class object.
static void * operator new (nom::size_type mem)
static void operator delete (void *ptr)
Static Public Attributes inherited from nom::IObject
static uint64 total_alloc_bytes
static uint64 total_dealloc_bytes

Detailed Description

Extended sprite rendering using sprite sheets.

Definition at line 42 of file SpriteBatch.hpp.

Member Typedef Documentation

◆ derived_class

typedef Sprite nom::SpriteBatch::derived_class

Definition at line 46 of file SpriteBatch.hpp.

◆ self_type

typedef SpriteBatch nom::SpriteBatch::self_type

Definition at line 45 of file SpriteBatch.hpp.

Constructor & Destructor Documentation

◆ SpriteBatch()

nom::SpriteBatch::SpriteBatch ( )

Default construct for initializing instance variables to their respective defaults.

Todo
Consider initializing sheet_id_ to -1..?

Member Function Documentation

◆ draw() [1/2]

virtual void nom::SpriteBatch::draw ( IDrawable::RenderTarget & target) const
overridevirtual

Render the sprite frame.

Remarks
The sprite is not rendered when the frame number is negative one (-1).
Note
Re-implements Sprite::draw.

Reimplemented from nom::Sprite.

◆ draw() [2/2]

virtual void nom::SpriteBatch::draw ( RenderTarget & target,
real64 angle ) const
overridevirtual

Render the sprite frame at an angle.

Remarks
The sprite is not rendered when the frame number is negative one (-1).
Note
Re-implements Sprite::draw.

Reimplemented from nom::Sprite.

◆ set_frame()

void nom::SpriteBatch::set_frame ( int32 id)

Set a new frame ID to render.

Parameters
idThe frame identifier (from the sprite sheet) to use in rendering.
Remarks
Setting the frame number to negative one (-1) will prevent updating and rendering of the object. This can be used to effectively toggle visibility of a sprite without the need of using a placeholder frame in the image source.
See also
::update.

◆ set_sprite_sheet()

virtual void nom::SpriteBatch::set_sprite_sheet ( const SpriteSheet & sheet)
virtual

Use the sprite frames from an existing SpriteSheet object.

Parameters
sheetThe pre-loaded sprite sheet instance to use the frames from.
Remarks
The dimensions of this object's Sprite instance are initialized to the first frame of the sprite sheet source.
See also
nom::SpriteSheet::load_file.

◆ type()

ObjectTypeInfo nom::SpriteBatch::type ( ) const
overridevirtual

Re-implements the IObject::type method.

Remarks
This uniquely identifies the object's type.

Reimplemented from nom::Sprite.

◆ update()

virtual void nom::SpriteBatch::update ( )
overrideprivatevirtual

Update the sprite for rendering with regard to positioning coordinates and target frame ID.

Remarks
The sprite is not updated when the frame number is negative one (-1).

Reimplemented from nom::Sprite.

Member Data Documentation

◆ offsets

IntRect nom::SpriteBatch::offsets
protected

Source (input) coordinates – used for sprite sheet positioning.

Definition at line 113 of file SpriteBatch.hpp.

◆ sheet_id_

int32 nom::SpriteBatch::sheet_id_
protected

The sheet's frame ID presently in use.

Definition at line 119 of file SpriteBatch.hpp.

◆ sprite_sheet

SpriteSheet nom::SpriteBatch::sprite_sheet
protected

Our attached sprite sheet object.

Definition at line 116 of file SpriteBatch.hpp.


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