#include <JSprite.h>
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) |
JQuad * | GetCurrentFrame () |
int | GetFrameCount () |
JQuad * | GetFrame (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) |
Type of animation.
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.
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. |
virtual void JSprite::Update | ( | float | dt | ) | [virtual] |
Update animation.
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.
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.
f | - True to enable, false to disable. |
bool JSprite::IsActive | ( | ) |
Get current active status.
void JSprite::SetId | ( | int | id | ) |
Give sprite an id.
id | - Id. |
int JSprite::GetId | ( | ) |
Get sprite id.
void JSprite::SetFlip | ( | bool | flip, | |
int | index = -1 | |||
) |
Flip a frame or all frames horizontally when rendering.
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.
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.
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.
duration | - Playback duration (in second) for each frame. |
int JSprite::GetCurrentFrameIndex | ( | ) |
Get index of current frame.
void JSprite::SetCurrentFrameIndex | ( | int | frame | ) |
Set current frame to a particular index.
frame | - The new index of current frame. |
JQuad* JSprite::GetCurrentFrame | ( | ) |
Get current frame image (quad).
int JSprite::GetFrameCount | ( | ) |
Get numer of animation frames.
JQuad* JSprite::GetFrame | ( | int | index | ) |
Get frame image (quad).
void JSprite::RestartAnimation | ( | ) |
Restart animation.
void JSprite::StartAnimation | ( | ) |
Start animation.
void JSprite::StopAnimation | ( | ) |
Stop animation.
bool JSprite::IsAnimating | ( | ) |
Get animation status.
void JSprite::Move | ( | float | x, | |
float | y | |||
) |
Move some distance from the current position.
x | - X distance to move. | |
y | - Y distance to move. |
void JSprite::SetPosition | ( | float | x, | |
float | y | |||
) |
Set position of the sprite.
x | - X position. | |
y | - Y position. |
void JSprite::SetX | ( | float | x | ) |
Set X position of the sprite.
x | - X position. |
void JSprite::SetY | ( | float | y | ) |
Set Y position of the sprite.
y | - Y position. |
float JSprite::GetX | ( | ) |
Get X position of the sprite.
float JSprite::GetY | ( | ) |
Get Y position of the sprite.
float JSprite::GetXVelocity | ( | ) |
Get X velocity.
float JSprite::GetYVelocity | ( | ) |
Get Y velocity.
void JSprite::SetAlpha | ( | float | alpha | ) |
Set alpha value for rendering.
alpha | - Alpha value. |
float JSprite::GetAlpha | ( | ) |
Get alpha value.
void JSprite::SetScale | ( | float | hscale, | |
float | vscale | |||
) |
Set scale of the sprite.
hscale | - Horizontal scale. | |
vscale | - Vertical scale. |
void JSprite::SetScale | ( | float | scale | ) |
Set scale of the sprite.
scale | - Scale for both horizontal and vertical dimension. |
float JSprite::GetScale | ( | ) |
Get scale of the sprite.
void JSprite::SetRotation | ( | float | rot | ) |
Set rotation factor of the sprite.
rot | - Rotation angle in radian. |
float JSprite::GetRotation | ( | ) |
Get rotation factor of the sprite.
void JSprite::SetSpeed | ( | float | speed | ) |
Set moving speed of the sprite.
speed | - Moving speed. |
float JSprite::GetSpeed | ( | ) |
Get moving speed of the sprite.
void JSprite::SetDirection | ( | float | angle | ) |
Set moving direction of the sprite.
angle | - Moving angle in radian. |
void JSprite::SetDirection | ( | float | x, | |
float | y | |||
) |
Set moving direction of the sprite based on a targeting position.
x | - X position of the target. | |
y | - Y position of the target. |
float JSprite::GetDirection | ( | ) |
Get moving direction of the sprite.
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.
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.
color | - Color. |