Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

Sprite Class Reference

#include <sprite.h>

List of all members.


Detailed Description

NOTE: Sprite calls CreateSurface and FreeSurface as necessary! If you pass a Surface * argument, you must free it afterwards because Sprite will create a copy of it and free it when sprite goes out of scope. CM

Definition at line 14 of file sprite.h.

Public Methods

 Sprite (string sprname="")
 Creates a sprite with no frames.

 Sprite (string filename, string sprname="")
 Creates a sprite from filename named sprname.

 Sprite (vector< string > &filenames, string sprname="")
 Creates a sprite using filenames.

 Sprite (Surface *frame, string sprname="")
 Creates a sprite from an already allocated surface.

 Sprite (vector< Surface * > &sframes, string sprname="")
 Creates a sprite from a series of surfaces.

 Sprite (const Sprite &)
 Copy Constructor.

virtual ~Sprite ()
 Virtual delete.

virtual void animate ()
 changes frame and other information

virtual Rect draw (Graphics &)
 knows how to draw to a graphics context

virtual Rect draw (Surface *)
 Knows how to draw to a surface.

void ReverseAnimation (bool)
void EnableAnimation (bool)
 Enable/Disable animation.

void ToggleAnimation ()
 Toggles animation.

void SetAnimateTime (int ms)
 Sets time per frame of animation.

void SetAnimationStartFrame (int)
 delay between calling animate Sets the start frame for the animation

void SetAnimationEndFrame (int)
 Sets th stop frame for the animation (should be 1 + the last).

void Show (bool)
 Show/Hide the sprite.

void SetFrame (int)
 Sets the frame to draw, when not in animation mode.

int GetFrame () const
 Returns current frame drawn.

int CountFrames ()
 Returns the amount of frames for this sprite.

virtual int SetPosition (double x=0.0, double y=0.0)
 Set the position of the sprite.

string GetName () const
 Return the name of the sprite.

void SetName (string)
 Set the name.

Sprite & operator++ ()
Sprite operator++ (int)
Sprite & operator-- ()
 Decreases drawn frame, will loop.

Sprite operator-- (int)
Sprite & operator= (int)
 Sets the frame to draw (calls SetFrame).

int GetWidth () const
int GetHeight () const
double GetX () const
double GetY () const
int LoadFrames (vector< Surface * > &sframes)
int LoadFrames (vector< string > &filenames)
int LoadFrame (Surface *frame)
int LoadFrame (string filename)
int AddFrame (Surface *frame)
 Add functions append to the old frames vector.

int AddFrame (string filename)
int AppendFrame (Surface *frame)
 Append functions don't duplicate existing memory.

bool RemoveFrame (int)
 Removes the frame at position.

bool EmptyFrames ()
 Frees all frames.


Static Public Attributes

SpriteCache cache

Protected Methods

void init ()
 More Utilities.

void close ()

Private Attributes

vector< Surface * > frames
bool free_frames_on_exit
unsigned int current_frame
double x
double y
int w
int h
string name
 Name of the sprite.

bool visible
 Optional name for the sprite.

Sprite::_animinfo animinfo


Constructor & Destructor Documentation

Sprite::Sprite string    sprname = ""
 

Creates a sprite with no frames.

Definition at line 13 of file sprite.cpp.

References init(), and SetName().

Sprite::Sprite string    filename,
string    sprname = ""
 

Creates a sprite from filename named sprname.

Definition at line 21 of file sprite.cpp.

References init(), LoadFrame(), and SetName().

Sprite::Sprite vector< string > &    filenames,
string    sprname = ""
 

Creates a sprite using filenames.

Definition at line 31 of file sprite.cpp.

References init(), LoadFrames(), and SetName().

Sprite::Sprite Surface   frame,
string    sprname = ""
 

Creates a sprite from an already allocated surface.

Definition at line 41 of file sprite.cpp.

References init(), LoadFrame(), and SetName().

Sprite::Sprite vector< Surface * > &    sframes,
string    sprname = ""
 

Creates a sprite from a series of surfaces.

Definition at line 51 of file sprite.cpp.

References init(), LoadFrames(), and SetName().

Sprite::Sprite const Sprite &   
 

Copy Constructor.

Definition at line 61 of file sprite.cpp.

Sprite::~Sprite   [virtual]
 

Virtual delete.

Definition at line 68 of file sprite.cpp.

References close().


Member Function Documentation

int Sprite::AddFrame string    filename
 

Definition at line 375 of file sprite.cpp.

References cache, SpriteCache::Find(), and frames.

int Sprite::AddFrame Surface   frame
 

Add functions append to the old frames vector.

Definition at line 361 of file sprite.cpp.

References frames.

Referenced by LoadFrame(), and LoadFrames().

void Sprite::animate   [virtual]
 

changes frame and other information

Definition at line 103 of file sprite.cpp.

References animinfo, current_frame, Sprite::_animinfo::delay, Sprite::_animinfo::enabled, Sprite::_animinfo::end_frame, Sprite::_animinfo::lastanimtime, Sprite::_animinfo::reverse, SetFrame(), Sprite::_animinfo::start_frame, and Util_TimePassed().

int Sprite::AppendFrame Surface   frame
 

Append functions don't duplicate existing memory.

void Sprite::close   [protected]
 

Definition at line 90 of file sprite.cpp.

References EmptyFrames(), and frames.

Referenced by ~Sprite().

int Sprite::CountFrames  
 

Returns the amount of frames for this sprite.

Definition at line 250 of file sprite.cpp.

References frames.

Referenced by operator++(), operator--(), and Crosshair::think().

Rect Sprite::draw Surface   [virtual]
 

Knows how to draw to a surface.

Definition at line 148 of file sprite.cpp.

References Graphics::blit(), current_frame, frames, GetX(), GetY(), h, Rect, visible, and w.

Rect Sprite::draw Graphics   [virtual]
 

knows how to draw to a graphics context

Definition at line 127 of file sprite.cpp.

References Graphics::blit(), current_frame, frames, GetX(), GetY(), h, Rect, visible, and w.

bool Sprite::EmptyFrames  
 

Frees all frames.

Definition at line 401 of file sprite.cpp.

References frames, and Graphics::freeImage().

Referenced by close(), LoadFrame(), and LoadFrames().

void Sprite::EnableAnimation bool   
 

Enable/Disable animation.

Definition at line 181 of file sprite.cpp.

References animinfo, Sprite::_animinfo::enabled, Sprite::_animinfo::lastanimtime, and Util_GetTime().

Referenced by Bear::Bear(), init(), Bear::setWalk(), MainChar::setWalking(), and ToggleAnimation().

int Sprite::GetFrame   const
 

Returns current frame drawn.

Definition at line 243 of file sprite.cpp.

References current_frame.

Referenced by operator++(), operator--(), Crosshair::SetPosition(), MainChar::setWalking(), and Crosshair::think().

int Sprite::GetHeight   const [inline]
 

Definition at line 104 of file sprite.h.

References w.

Referenced by GameObject::GetBoundingRect(), GameObject::Recenter(), MainChar::Recenter(), Crosshair::Recenter(), MainChar::setLook(), and Bear::setWalk().

string Sprite::GetName   const
 

Return the name of the sprite.

Definition at line 257 of file sprite.cpp.

References name.

int Sprite::GetWidth   const [inline]
 

Definition at line 103 of file sprite.h.

Referenced by MainChar::FireWeapon(), GameObject::GetBoundingRect(), MainChar::Recenter(), Crosshair::Recenter(), MainChar::setLook(), and Bear::setWalk().

double Sprite::GetX   const [inline]
 

Definition at line 105 of file sprite.h.

References h.

Referenced by draw(), GameObject::GetBoundingRect(), MainChar::setLook(), and Bear::setWalk().

double Sprite::GetY   const [inline]
 

Definition at line 106 of file sprite.h.

References x.

Referenced by draw(), GameObject::GetBoundingRect(), MainChar::setLook(), and Bear::setWalk().

void Sprite::init   [protected]
 

More Utilities.

Definition at line 73 of file sprite.cpp.

References EnableAnimation(), frames, free_frames_on_exit, SetFrame(), SetPosition(), and Show().

Referenced by Sprite().

int Sprite::LoadFrame string    filename
 

Definition at line 355 of file sprite.cpp.

References AddFrame(), and EmptyFrames().

int Sprite::LoadFrame Surface   frame
 

Definition at line 349 of file sprite.cpp.

References AddFrame(), and EmptyFrames().

Referenced by Sprite().

int Sprite::LoadFrames vector< string > &    filenames
 

Definition at line 337 of file sprite.cpp.

References AddFrame(), and EmptyFrames().

int Sprite::LoadFrames vector< Surface * > &    sframes
 

Loads frames in different manners Load* functions destroy the old frames vector

Definition at line 325 of file sprite.cpp.

References AddFrame(), and EmptyFrames().

Referenced by Sprite().

Sprite Sprite::operator++ int   
 

Definition at line 282 of file sprite.cpp.

References CountFrames(), GetFrame(), and SetFrame().

Sprite & Sprite::operator++  
 

Operators Increases drawn frame, will loop frames

Definition at line 275 of file sprite.cpp.

References CountFrames(), GetFrame(), and SetFrame().

Sprite Sprite::operator-- int   
 

Definition at line 301 of file sprite.cpp.

References CountFrames(), GetFrame(), and SetFrame().

Sprite & Sprite::operator--  
 

Decreases drawn frame, will loop.

Definition at line 291 of file sprite.cpp.

References CountFrames(), GetFrame(), and SetFrame().

Sprite & Sprite::operator= int   
 

Sets the frame to draw (calls SetFrame).

Definition at line 314 of file sprite.cpp.

References SetFrame().

bool Sprite::RemoveFrame int   
 

Removes the frame at position.

Definition at line 387 of file sprite.cpp.

References frames, and Graphics::freeImage().

void Sprite::ReverseAnimation bool   
 

Utility functions Enable/Disable reverse animation

Definition at line 174 of file sprite.cpp.

References animinfo, and Sprite::_animinfo::reverse.

Referenced by Bear::Bear(), Bear::setWalk(), and MainChar::setWalking().

void Sprite::SetAnimateTime int    ms
 

Sets time per frame of animation.

Definition at line 200 of file sprite.cpp.

References animinfo, and Sprite::_animinfo::delay.

Referenced by Bear::Bear(), MainChar::MainChar(), and Bear::setWalk().

void Sprite::SetAnimationEndFrame int   
 

Sets th stop frame for the animation (should be 1 + the last).

Definition at line 214 of file sprite.cpp.

References animinfo, and Sprite::_animinfo::end_frame.

Referenced by Bear::Bear(), Bear::setWalk(), and MainChar::setWalking().

void Sprite::SetAnimationStartFrame int   
 

delay between calling animate Sets the start frame for the animation

Definition at line 207 of file sprite.cpp.

References animinfo, and Sprite::_animinfo::start_frame.

Referenced by Bear::Bear(), Bear::setWalk(), and MainChar::setWalking().

void Sprite::SetFrame int   
 

Sets the frame to draw, when not in animation mode.

Definition at line 225 of file sprite.cpp.

References current_frame, frames, h, and w.

Referenced by animate(), Bear::Bear(), MainChar::ChangeDirection(), Crosshair::Crosshair(), init(), MainChar::MainChar(), operator++(), operator--(), operator=(), UFO::SetupDirection(), Bear::setWalk(), and MainChar::setWalking().

void Sprite::SetName string   
 

Set the name.

Definition at line 264 of file sprite.cpp.

References name.

Referenced by Sprite().

int Sprite::SetPosition double    x = 0.0,
double    y = 0.0
[virtual]
 

Set the position of the sprite.

Definition at line 235 of file sprite.cpp.

References x, and y.

Referenced by init(), GameObject::Recenter(), MainChar::Recenter(), and Crosshair::Recenter().

void Sprite::Show bool   
 

Show/Hide the sprite.

Definition at line 219 of file sprite.cpp.

References visible.

Referenced by init().

void Sprite::ToggleAnimation  
 

Toggles animation.

Definition at line 193 of file sprite.cpp.

References animinfo, EnableAnimation(), and Sprite::_animinfo::enabled.


Member Data Documentation

struct Sprite::_animinfo Sprite::animinfo [private]
 

Referenced by animate(), EnableAnimation(), ReverseAnimation(), SetAnimateTime(), SetAnimationEndFrame(), SetAnimationStartFrame(), and ToggleAnimation().

SpriteCache Sprite::cache [static]
 

Definition at line 6 of file sprite.cpp.

Referenced by AddFrame(), and Util_parseImage().

unsigned int Sprite::current_frame [private]
 

Definition at line 138 of file sprite.h.

Referenced by animate(), draw(), GetFrame(), and SetFrame().

vector<Surface *> Sprite::frames [private]
 

Definition at line 135 of file sprite.h.

Referenced by AddFrame(), close(), CountFrames(), draw(), EmptyFrames(), init(), RemoveFrame(), and SetFrame().

bool Sprite::free_frames_on_exit [private]
 

Definition at line 136 of file sprite.h.

Referenced by init().

int Sprite::h [private]
 

Definition at line 140 of file sprite.h.

Referenced by draw(), GetX(), and SetFrame().

string Sprite::name [private]
 

Name of the sprite.

Definition at line 143 of file sprite.h.

Referenced by GetName(), and SetName().

bool Sprite::visible [private]
 

Optional name for the sprite.

Definition at line 145 of file sprite.h.

Referenced by draw(), and Show().

int Sprite::w [private]
 

Definition at line 140 of file sprite.h.

Referenced by draw(), GetHeight(), and SetFrame().

double Sprite::x [private]
 

Definition at line 139 of file sprite.h.

Referenced by GetY(), and SetPosition().

double Sprite::y [private]
 

Definition at line 139 of file sprite.h.

Referenced by SetPosition().


The documentation for this class was generated from the following files:
Generated on Sun Dec 8 12:02:22 2002 for nnc by doxygen1.3-rc1