#include <JAnimator.h>
Public Member Functions | |
JAnimator (JResourceManager *resourceMgr) | |
~JAnimator () | |
bool | Load (const char *scriptFile) |
void | Start () |
void | Stop () |
void | Pause () |
void | Resume () |
void | Update (float dt) |
void | Render () |
bool | IsAnimating () |
bool | IsActive () |
void | SetCurrentFrameIndex (int index) |
int | GetCurrentFrameIndex () |
void | SetAnimationType (int type) |
void | SetPosition (float x, float y) |
void | SetHotSpot (float x, float y) |
A sample animation script:
<?xml version="1.0" standalone="no" ?> <script name="abc" type="ANIMATION_TYPE_ONCE_AND_STAY" framerate="20">
"type" can be ANIMATION_TYPE_LOOPING, ANIMATION_TYPE_ONCE_AND_STAY, ANIMATION_TYPE_ONCE_AND_BACK, ANIMATION_TYPE_ONCE_AND_GONE or ANIMATION_TYPE_PINGPONG
"framerate" is the rate of playback in frames per seconds.
<frame id="1"> <obj name="head"> <settings quad="head" x="10" y="10" hsize="1.0" vsize="1.0" rotation="0.0" r="255" g="255" b="255" a="255" /> </obj> <obj name="body"> <settings quad="body" /> </obj> </frame>
Each frame contains one or more frame objects. Each object is a quad with various settings. "quad" is the name of the quad. "x" and "y" is the position. "hsize" is the horizontal scaling and "vsize" is the vertical scaling. "rotation" is the angle that the quad will be rotated in radians. You can also specify the color and alpha of the quad with the "r", "g", "b" and "a" parameters.
<frame id="2" time="0.20"> <obj name="head"> <settings quad="head" x="10" y="10" hsize="1.0" vsize="1.0" rotation="0.0" r="255" g="255" b="255" a="255" /> </obj> <obj name="body"> <settings quad="body" a="128" /> </obj> </frame> </script>
A frame can also overide the global frame rate by using the "time" parameter (in second) as shown above.
JAnimator::JAnimator | ( | JResourceManager * | resourceMgr | ) |
Constructor.
resourceMgr | - ResourceManager to look for images (JQuads) |
JAnimator::~JAnimator | ( | ) |
Destructor.
bool JAnimator::Load | ( | const char * | scriptFile | ) |
Load animation sequence from a script file.
scriptFile | - Animation script. |
void JAnimator::Start | ( | ) |
Start animation.
void JAnimator::Stop | ( | ) |
Stop animation.
void JAnimator::Pause | ( | ) |
Pause animation.
void JAnimator::Resume | ( | ) |
Resume animation.
void JAnimator::Update | ( | float | dt | ) |
Update animation.
dt | - Time elapsed since last update (in second). |
void JAnimator::Render | ( | ) |
Render animation.
bool JAnimator::IsAnimating | ( | ) |
Check if animation is playing or not.
bool JAnimator::IsActive | ( | ) |
Check if the animation is active.
void JAnimator::SetCurrentFrameIndex | ( | int | index | ) |
Set current frame to a particular index.
index | - The new index of current frame. |
int JAnimator::GetCurrentFrameIndex | ( | ) |
Get index of current frame.
void JAnimator::SetAnimationType | ( | int | type | ) |
Set animation type.
type | - Animation type. |
void JAnimator::SetPosition | ( | float | x, | |
float | y | |||
) |
Set position of the sprite.
x | - X position. | |
y | - Y position. |
void JAnimator::SetHotSpot | ( | float | x, | |
float | y | |||
) |
Set anchor point of the animation. All rendering operations will be based on this anchor point.
x | - X position of the anchor point. | |
y | - Y position of the anchor point. |