JSprite Class Reference

#include <JSprite.h>

Inheritance diagram for JSprite:
Collaboration diagram for JSprite:

List of all members.

Public Types

enum  ANIMATION_TYPE {
  ANIMATION_TYPE_LOOPING, ANIMATION_TYPE_ONCE_AND_STAY, ANIMATION_TYPE_ONCE_AND_BACK, ANIMATION_TYPE_ONCE_AND_GONE,
  ANIMATION_TYPE_PINGPONG
}

Public Member Functions

 JSprite (JTexture *tex=NULL, float x=0.0f, float y=0.0f, float width=0.0f, float height=0.0f, bool flipped=false)
virtual void Update (float dt)
virtual void Render ()
void SetAnimationType (int type)
void SetActive (bool f)
bool IsActive ()
void SetId (int id)
int GetId ()
void SetFlip (bool flip, int index=-1)
void AddFrame (float x, float y, float width, float height, bool flipped=false)
void AddFrame (JTexture *tex, float x, float y, float width, float height, bool flipped=false)
void SetDuration (float duration)
int GetCurrentFrameIndex ()
void SetCurrentFrameIndex (int frame)
JQuadGetCurrentFrame ()
int GetFrameCount ()
JQuadGetFrame (int index)
void RestartAnimation ()
void StartAnimation ()
void StopAnimation ()
bool IsAnimating ()
void Move (float x, float y)
void SetPosition (float x, float y)
void SetX (float x)
void SetY (float y)
float GetX ()
float GetY ()
float GetXVelocity ()
float GetYVelocity ()
void SetAlpha (float alpha)
float GetAlpha ()
void SetScale (float hscale, float vscale)
void SetScale (float scale)
float GetScale ()
void SetRotation (float rot)
float GetRotation ()
void SetSpeed (float speed)
float GetSpeed ()
void SetDirection (float angle)
void SetDirection (float x, float y)
float GetDirection ()
void SetHotSpot (float x, float y, int index=-1)
void SetColor (PIXEL_TYPE color)


Detailed Description

Sprite is a container of single static image or animation frames.

Member Enumeration Documentation

enum JSprite::ANIMATION_TYPE

Type of animation.

Enumerator:
ANIMATION_TYPE_LOOPING  Repeat playing (Default).
ANIMATION_TYPE_ONCE_AND_STAY  Play to the end and stay at last frame.
ANIMATION_TYPE_ONCE_AND_BACK  Play to end and then stay at first frame.
ANIMATION_TYPE_ONCE_AND_GONE  Play animation once only.
ANIMATION_TYPE_PINGPONG  Play forward then backward and repeat.


Constructor & Destructor Documentation

JSprite::JSprite ( JTexture *  tex = NULL,
float  x = 0.0f,
float  y = 0.0f,
float  width = 0.0f,
float  height = 0.0f,
bool  flipped = false 
)

Constructor.

Parameters:
tex - Texture for the first frame and the following frames. NULL to indicate no starting frame.
x - X of the frame in texture.
y - Y of the frame in texture.
width - Width of the frame.
height - Height of the frame.
flipped - Indicate if the frame is horizontally flipped.


Member Function Documentation

virtual void JSprite::Update ( float  dt  )  [virtual]

Update animation.

Parameters:
dt - Delta time since last update (in second).

Reimplemented in JGameObject.

virtual void JSprite::Render (  )  [virtual]

Render current frame.

Reimplemented in JGameObject.

void JSprite::SetAnimationType ( int  type  ) 

Set animation type.

Parameters:
type - Animation type.
                ANIMATION_TYPE_LOOPING - Repeat playing (Default).
                ANIMATION_TYPE_ONCE_AND_GONE - Play animation once only.
                ANIMATION_TYPE_ONCE_AND_BACK - Play to end and then stay at first frame.
                ANIMATION_TYPE_PINGPONG - Play forward then backward and repeat.

void JSprite::SetActive ( bool  f  ) 

Enable/Disable sprite.

Parameters:
f - True to enable, false to disable.

bool JSprite::IsActive (  ) 

Get current active status.

Returns:
Active status.

void JSprite::SetId ( int  id  ) 

Give sprite an id.

Parameters:
id - Id.

int JSprite::GetId (  ) 

Get sprite id.

Returns:
Sprite id.

void JSprite::SetFlip ( bool  flip,
int  index = -1 
)

Flip a frame or all frames horizontally when rendering.

Parameters:
flip - True to flip.
index - Frame index, -1 to flip all frames.

void JSprite::AddFrame ( float  x,
float  y,
float  width,
float  height,
bool  flipped = false 
)

Add new animation frame.

Parameters:
x - X of the frame in texture.
y - Y of the frame in texture.
width - Width of the frame.
height - Height of the frame.
flipped - Indicate if the frame is horizontally flipped.

void JSprite::AddFrame ( JTexture *  tex,
float  x,
float  y,
float  width,
float  height,
bool  flipped = false 
)

Add new animation frame.

Parameters:
tex - Texture for this frame and the following frames.
x - X of the frame in texture.
y - Y of the frame in texture.
width - Width of the frame.
height - Height of the frame.
flipped - Indicate if the frame is horizontally flipped.

void JSprite::SetDuration ( float  duration  ) 

Set playback duration for each frame.

Parameters:
duration - Playback duration (in second) for each frame.

int JSprite::GetCurrentFrameIndex (  ) 

Get index of current frame.

Returns:
Index of current frame.

void JSprite::SetCurrentFrameIndex ( int  frame  ) 

Set current frame to a particular index.

Parameters:
frame - The new index of current frame.

JQuad* JSprite::GetCurrentFrame (  ) 

Get current frame image (quad).

Returns:
Quad object.

int JSprite::GetFrameCount (  ) 

Get numer of animation frames.

Returns:
Numer of animation frames.

JQuad* JSprite::GetFrame ( int  index  ) 

Get frame image (quad).

Returns:
Quad object.

void JSprite::RestartAnimation (  ) 

Restart animation.

void JSprite::StartAnimation (  ) 

Start animation.

void JSprite::StopAnimation (  ) 

Stop animation.

bool JSprite::IsAnimating (  ) 

Get animation status.

Returns:
animation status

void JSprite::Move ( float  x,
float  y 
)

Move some distance from the current position.

Parameters:
x - X distance to move.
y - Y distance to move.

void JSprite::SetPosition ( float  x,
float  y 
)

Set position of the sprite.

Parameters:
x - X position.
y - Y position.

void JSprite::SetX ( float  x  ) 

Set X position of the sprite.

Parameters:
x - X position.

void JSprite::SetY ( float  y  ) 

Set Y position of the sprite.

Parameters:
y - Y position.

float JSprite::GetX (  ) 

Get X position of the sprite.

Returns:
X position.

float JSprite::GetY (  ) 

Get Y position of the sprite.

Returns:
Y position.

float JSprite::GetXVelocity (  ) 

Get X velocity.

Returns:
X velocity.

float JSprite::GetYVelocity (  ) 

Get Y velocity.

Returns:
Y velocity.

void JSprite::SetAlpha ( float  alpha  ) 

Set alpha value for rendering.

Parameters:
alpha - Alpha value.

float JSprite::GetAlpha (  ) 

Get alpha value.

Returns:
Alpha value.

void JSprite::SetScale ( float  hscale,
float  vscale 
)

Set scale of the sprite.

Parameters:
hscale - Horizontal scale.
vscale - Vertical scale.

void JSprite::SetScale ( float  scale  ) 

Set scale of the sprite.

Parameters:
scale - Scale for both horizontal and vertical dimension.

float JSprite::GetScale (  ) 

Get scale of the sprite.

Returns:
Scale of horizontal (assume same as the vertical).

void JSprite::SetRotation ( float  rot  ) 

Set rotation factor of the sprite.

Parameters:
rot - Rotation angle in radian.

float JSprite::GetRotation (  ) 

Get rotation factor of the sprite.

Returns:
Rotation angle in radian.

void JSprite::SetSpeed ( float  speed  ) 

Set moving speed of the sprite.

Parameters:
speed - Moving speed.

float JSprite::GetSpeed (  ) 

Get moving speed of the sprite.

Returns:
Moving speed.

void JSprite::SetDirection ( float  angle  ) 

Set moving direction of the sprite.

Parameters:
angle - Moving angle in radian.

void JSprite::SetDirection ( float  x,
float  y 
)

Set moving direction of the sprite based on a targeting position.

Parameters:
x - X position of the target.
y - Y position of the target.

float JSprite::GetDirection (  ) 

Get moving direction of the sprite.

Returns:
Moving angle in radian.

void JSprite::SetHotSpot ( float  x,
float  y,
int  index = -1 
)

Set anchor point of a frame or all frames of the sprite. All rotation and collision operations are based on this anchor point.

Parameters:
x - X position of the anchor point.
y - Y position of the anchor point.
index - Frame index, -1 for all frames.

void JSprite::SetColor ( PIXEL_TYPE  color  ) 

Set color of the sprite for rendering.

Parameters:
color - Color.


Generated on Mon Oct 22 00:28:23 2007 for JGE++ by  doxygen 1.5.3