sftools  2.0 dev
Bunch of tools for SFML application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Public Types | Public Member Functions | List of all members
sftools::LoopFrameStream Class Reference

Define a animation's frame stream based on a sprite sheet. More...

#include <LoopFrameStream.hpp>

+ Collaboration diagram for sftools::LoopFrameStream:

Classes

struct  Settings
 Combine horizontal, vertical and precedence policies together to define how a sprite sheet should be read. More...
 

Public Types

enum  HorizontalStartFromPolicy { FromLeft = 0, FromRight }
 Define how a sprite sheet should be horitontally read. More...
 
enum  VerticalStartFromPolicy { FromTop = 0, FromBottom }
 Define how a sprite sheet should be vertically read. More...
 
enum  PrecedencePolicy { HorizontalFirst = 0, VerticalFirst }
 Define how a sprite sheet should be read. More...
 

Public Member Functions

 LoopFrameStream ()
 Default constructor.
 
 LoopFrameStream (LoopFrameStream const &stream)
 Copy constructor.
 
 LoopFrameStream (sf::Texture const &texture, sf::Vector2i frameSize, sf::Vector2u frameCount, sf::Time frameTime, bool loop=true, Settings const &settings=Settings())
 Constructor.
 
LoopFrameStreamoperator= (LoopFrameStream const &rhs)
 Copy assignment operator.
 
void create (sf::Texture const &texture, sf::Vector2i frameSize, sf::Vector2u frameCount, sf::Time frameTime, bool loop=true, Settings const &settings=Settings())
 Load a sprite sheet.
 
virtual Frame getFrameAt (sf::Time time) const
 Seek and fetch a frame at a given point in time.
 

Detailed Description

Define a animation's frame stream based on a sprite sheet.

Note
Like sf::Sprite, LoopFrameStream doesn't own the texture. You have to keep it 'alive' for the lifetime of the stream that uses it, otherwise you'll get some undefined behaviour.
Todo:
It could be usefull to provide a 'combine(LoopFrameStream)' method to use more than one sprite sheet for an animation.
Todo:
In the same vein a 'add(Frame)' or 'add(begin, end)' could be useful too.
Todo:
Does 'loop == false' means the animation should keep displaying the last frame or display nothing at all when the last frame is reached ? Currently the first solution is implemented but it might be more cleaver to implement the second one. Or add a LoopPolicy..
See Also
FrameStream
Animation
Frame

Definition at line 70 of file LoopFrameStream.hpp.

Member Enumeration Documentation

Define how a sprite sheet should be horitontally read.

i.e. from left to right or from right to left ?

See Also
LoopFrameStream::Settings
VerticalStartFromPolicy
PrecedencePolicy
Enumerator
FromLeft 

Read the sprite sheet from left to right.

FromRight 

Read the sprite sheet from right to left.

Definition at line 83 of file LoopFrameStream.hpp.

Define how a sprite sheet should be read.

i.e. by row or by column ?

See Also
LoopFrameStream::Settings
VerticalStartFromPolicy
HorizontalStartFromPolicy
Enumerator
HorizontalFirst 

Read the sprite sheet by row.

VerticalFirst 

Read the sprite sheet by column.

Definition at line 115 of file LoopFrameStream.hpp.

Define how a sprite sheet should be vertically read.

i.e. from top to bottom or from bottom to top ?

See Also
LoopFrameStream::Settings
HorizontalStartFromPolicy
PrecedencePolicy
Enumerator
FromTop 

Read the sprite sheet from top to bottom.

FromBottom 

Read the sprite sheet from bottom to top.

Definition at line 99 of file LoopFrameStream.hpp.

Constructor & Destructor Documentation

sftools::LoopFrameStream::LoopFrameStream ( )
inline

Default constructor.

Doesn't load any frame at all.

Note
You must call create() at least once before usign this stream in an animation

Definition at line 163 of file LoopFrameStream.hpp.

sftools::LoopFrameStream::LoopFrameStream ( LoopFrameStream const &  stream)
inline

Copy constructor.

Parameters
streamobject to copy

Definition at line 175 of file LoopFrameStream.hpp.

sftools::LoopFrameStream::LoopFrameStream ( sf::Texture const &  texture,
sf::Vector2i  frameSize,
sf::Vector2u  frameCount,
sf::Time  frameTime,
bool  loop = true,
Settings const &  settings = Settings() 
)
inline

Constructor.

Load a sprite sheet

Parameters
texturesprite sheet
frameSizesize of a frame
frameCountnumber of frame as a vector where x is the number of column and y is the number of row
frameTimetime by frame
loopdefine if the animation should loop or stay on the last frame
settingssettings used to read the sprite sheet
Exceptions
std::invalid_argumentif the number of frame is zero
std::invalid_argumentif the frame time is zero
See Also
create()

Definition at line 201 of file LoopFrameStream.hpp.

References create().

Member Function Documentation

void sftools::LoopFrameStream::create ( sf::Texture const &  texture,
sf::Vector2i  frameSize,
sf::Vector2u  frameCount,
sf::Time  frameTime,
bool  loop = true,
Settings const &  settings = Settings() 
)
inline

Load a sprite sheet.

Parameters
texturesprite sheet
frameSizesize of a frame
frameCountnumber of frame as a vector where x is the number of column and y is the number of row
frameTimetime by frame
loopdefine if the animation should loop or stay on the last frame
settingssettings used to read the sprite sheet
Exceptions
std::invalid_argumentif the number of frame is zero
std::invalid_argumentif the frame time is zero

Definition at line 240 of file LoopFrameStream.hpp.

References FromLeft, FromTop, and HorizontalFirst.

Referenced by LoopFrameStream().

virtual Frame sftools::LoopFrameStream::getFrameAt ( sf::Time  time) const
inlinevirtual

Seek and fetch a frame at a given point in time.

See FrameStream::getFrameAt() for more details.

Parameters
timetime elapsed since the start of the animation
Returns
the frame for the given point in time
Exceptions
std::runtime_errorif the stream was not yet loaded
See Also
FrameStream::getFrameAt()

Implements sftools::FrameStream.

Definition at line 308 of file LoopFrameStream.hpp.

LoopFrameStream& sftools::LoopFrameStream::operator= ( LoopFrameStream const &  rhs)
inline

Copy assignment operator.

Parameters
rhsstream to be copied
Returns
this stream

Definition at line 217 of file LoopFrameStream.hpp.


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