The Game Engine  1
Sprite Class Reference

Any independent 2D object to be displayed on screen with an animation. More...

#include <Sprite.h>

+ Inheritance diagram for Sprite:
+ Collaboration diagram for Sprite:

Public Member Functions

 Sprite (std::string name, Actor actor, bool menuSprite=false)
 
 ~Sprite ()
 
void setAnimation (int animation)
 Changes to the specified animation beginning at 0. More...
 
SpriteFramegetAnimation ()
 Returns active animation. More...
 
void setFrame (int frame)
 Changes to the specified frame of the animation beginning at 0. More...
 
int getFrame ()
 Returns active frame. More...
 
void setSpeed (float speed)
 Sets the Sprite's speed. More...
 
float getSpeed ()
 Returns a Sprite's current speed. More...
 
void toggleAnim ()
 Pauses or resumes an animation. More...
 
void startAnim ()
 Causes the animation to play. More...
 
void stopAnim ()
 Causes the animation to stop. More...
 
void rewind ()
 Resets the Sprite's animation to the first frame. More...
 
void draw ()
 Draws Sprite. More...
 
void drawCollisions ()
 Draws CollisionObject data for the Object (from outside) More...
 
virtual void update ()
 Updates that do not change (i.e. More...
 
virtual void runBehavior ()
 Update to state as well as child object states. More...
 
vector< Sprite * > collisionWithSprites (string name, int count=-1)
 Checks for collision with sprite of a given name. More...
 
vector< CollisionObject * > & getCollisionData ()
 Returns collision data. More...
 
Point2D getBasePos ()
 Obtain base position. More...
 
Point2D getCenterPos ()
 Obtain Center Pos for Collisions. More...
 
virtual WorldObjectType getType ()
 This provides a simple interface to determine types of objects. More...
 
- Public Member Functions inherited from WorldObject
 WorldObject (std::string name, Point2D pos=Point2D(), int z=0)
 
void drawCollisions (vector< CollisionObject * > &vec, const Point2D &pos)
 Draws CollisionObject data for the Object. More...
 
void setPosition (double x, double y)
 Sets the WorldObject's x an y coordinate. More...
 
void setPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate. More...
 
void setBasePosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setBasePosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void move (double dx=0.0, double dy=0.0)
 Move by given amount NOTE: This is an instantaneous movement by a given amount and does not correspond to physics which is set to do the updated amount per second. More...
 
virtual void move (Point2D direction)
 Moves the WorldObject relative to the current pos. More...
 
virtual void moveTowards (Point2D direction)
 Move towards a given coordinate (path finding) More...
 
Point2D getPosition ()
 Gets the WorldObject's position. More...
 
void setTransparency (float f)
 Sets the WorldObject's transparency. More...
 
float getTransparency ()
 Gets the WorldObject's transparency. More...
 
void setAngle (float a)
 Sets the WorldObject's angle in degrees. More...
 
float getAngle ()
 Gets the WorldObject's angle. More...
 
void setVelocity (Point2D vel)
 Sets the WorldObject's velocity as a vector (will set MaxVelocity if needed) More...
 
void setVelocity (double xVel, double yVel)
 Sets the WorldObject's velocity from coordinates (will set MaxVelocity if needed) More...
 
Point2D getVelocity ()
 Gets the WorldObject's Velocity. More...
 
void setMaxVelocity (Point2D vel)
 Sets the WorldObject's MaxVelocity (magnitude) from (x,y) and transforms into a magnitude. More...
 
void setMaxVelocity (double vel, Point2D dir)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
void setMaxSpeed (double vel)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
Point2D getMaxVelocity ()
 Gets the WorldObject's Max Velocity. More...
 
double getMaxSpeed ()
 Gets the WorldObject's Max Speed. More...
 
double getMaxSpeedSquared ()
 Gets the WorldObject's Max Speed Squared (cheaper operation). More...
 
void setAcceleration (Point2D accel)
 Sets the WorldObject's Acceleration in (x,y) coords. More...
 
Point2D getAcceleration ()
 Gets the WorldObject's Acceleration. More...
 
void setZOrder (int i)
 
int getZOrder ()
 
std::string getName ()
 returns the WorldObject's name More...
 
bool operator< (WorldObject &rhs)
 Sort worldObjects. More...
 

Protected Attributes

bool mAnimating
 Tells whether to animate or not. More...
 
bool mDrawn
 Tells if the object has been drawn the first time. More...
 
float mSpeed
 Movement speed of the Sprite. More...
 
Actor mActor
 This Sprite's Actor. More...
 
- Protected Attributes inherited from WorldObject
std::string mName
 WorldObject's name. More...
 
Point2D mPos
 The current (x,y) position. More...
 
Point2D mVelocity
 The current velocity vector. More...
 
Point2D mMaxVelocity
 The max velocity is the max possible velocity where lengthis the speed. More...
 
double mMaxSpeed
 The max Speed if MaxVelocity is 0 to store val. More...
 
Point2D mAcceleration
 The current acceleration vector. More...
 
bool mVisible
 Determine if Object should be visible. More...
 
float mTransparency
 Transparency! More...
 
float mAngle
 Angle of rotation. More...
 
float mScale
 Scale for the sprit. More...
 
int ZOrder
 Stacking order. Determines what draws on top. (subsorted by position) More...
 
long mLastUpdate
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
long mLastDraw
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
bool mUnused
 Determines whether or not this object's update function should run. More...
 
Behavior mBehavior
 Behavior to act each loop if !mUnused. More...
 

Additional Inherited Members

- Public Types inherited from WorldObject
enum  WorldObjectType {
  SPRITE, BACKGROUND, MENU, TEXT,
  PARTICLESYSTEM
}
 This is to be used for Type checking so as to make no need for dynamic_cast and it's inefficiency. More...
 

Detailed Description

Any independent 2D object to be displayed on screen with an animation.

This class is tasked with the following:

  • loading and controlling an Animation
    • Handling basic physics (Movement etc)
Todo:

make this be able to exist w/o loading all content

maybe rename to something else because this should also be the same thing used for 3D but with a model?

Definition at line 20 of file Sprite.h.

Constructor & Destructor Documentation

Sprite::Sprite ( std::string  name,
Actor  actor,
bool  menuSprite = false 
)

Definition at line 9 of file Sprite.cpp.

+ Here is the call graph for this function:

Sprite::~Sprite ( )

Member Function Documentation

vector< Sprite * > Sprite::collisionWithSprites ( string  name,
int  count = -1 
)

Checks for collision with sprite of a given name.

Todo:
if vals has items in it add each of them into the marked set

Definition at line 105 of file Sprite.cpp.

+ Here is the call graph for this function:

void Sprite::draw ( )
virtual

Draws Sprite.

Implements WorldObject.

Definition at line 25 of file Sprite.cpp.

+ Here is the call graph for this function:

void Sprite::drawCollisions ( )
virtual

Draws CollisionObject data for the Object (from outside)

Reimplemented from WorldObject.

Definition at line 97 of file Sprite.cpp.

+ Here is the call graph for this function:

SpriteFrame* Sprite::getAnimation ( )
inline

Returns active animation.

(actually the current frame within the animation)

Todo:
see if this is slower maybe undo
Returns
Pointer to the active Animation

Definition at line 36 of file Sprite.h.

+ Here is the caller graph for this function:

Point2D Sprite::getBasePos ( )
virtual

Obtain base position.

Implements WorldObject.

Definition at line 136 of file Sprite.cpp.

+ Here is the call graph for this function:

Point2D Sprite::getCenterPos ( )
virtual

Obtain Center Pos for Collisions.

Implements WorldObject.

Definition at line 141 of file Sprite.cpp.

+ Here is the call graph for this function:

vector< CollisionObject * > & Sprite::getCollisionData ( )

Returns collision data.

Definition at line 92 of file Sprite.cpp.

+ Here is the call graph for this function:

int Sprite::getFrame ( )
inline

Returns active frame.

Returns
The index representing the Active Frame

Definition at line 48 of file Sprite.h.

float Sprite::getSpeed ( )
inline

Returns a Sprite's current speed.

Returns
Speed of the Sprite

Definition at line 60 of file Sprite.h.

+ Here is the caller graph for this function:

virtual WorldObjectType Sprite::getType ( )
inlinevirtual

This provides a simple interface to determine types of objects.

Returns the name of the Class and Descendants i.e. Something inheriting from Sprite would look like Sprite:Thing

Implements WorldObject.

Definition at line 125 of file Sprite.h.

void Sprite::rewind ( )
inline

Resets the Sprite's animation to the first frame.

Definition at line 80 of file Sprite.h.

void Sprite::runBehavior ( )
virtual

Update to state as well as child object states.

Reimplemented from WorldObject.

Definition at line 86 of file Sprite.cpp.

+ Here is the call graph for this function:

void Sprite::setAnimation ( int  animation)
inline

Changes to the specified animation beginning at 0.

Parameters
animationThe index representing the animation to move to

Definition at line 30 of file Sprite.h.

void Sprite::setFrame ( int  frame)
inline

Changes to the specified frame of the animation beginning at 0.

Parameters
frameThe frame of the animation to move to

Definition at line 42 of file Sprite.h.

void Sprite::setSpeed ( float  speed)
inline

Sets the Sprite's speed.

Parameters
speedSpeed for the sprite (directly correlates to number of pixels)

Definition at line 54 of file Sprite.h.

+ Here is the caller graph for this function:

void Sprite::startAnim ( )
inline

Causes the animation to play.

Definition at line 70 of file Sprite.h.

void Sprite::stopAnim ( )
inline

Causes the animation to stop.

Definition at line 75 of file Sprite.h.

void Sprite::toggleAnim ( )
inline

Pauses or resumes an animation.

Definition at line 65 of file Sprite.h.

void Sprite::update ( )
virtual

Updates that do not change (i.e.

moving to the next frame, physics, etc.)

Reimplemented from WorldObject.

Definition at line 63 of file Sprite.cpp.

+ Here is the call graph for this function:

Member Data Documentation

Actor Sprite::mActor
protected

This Sprite's Actor.

Definition at line 138 of file Sprite.h.

bool Sprite::mAnimating
protected

Tells whether to animate or not.

Definition at line 129 of file Sprite.h.

bool Sprite::mDrawn
protected

Tells if the object has been drawn the first time.

Definition at line 132 of file Sprite.h.

float Sprite::mSpeed
protected

Movement speed of the Sprite.

Definition at line 135 of file Sprite.h.


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