major changes to control
This commit is contained in:
parent
2a4c8ed515
commit
18b0aa9954
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZAnimation.
|
\brief Source file for ZAnimation.
|
||||||
|
|
||||||
Implementation of ZAnimation, ZEngine's class for ZImage based animations.
|
Implementation of ZAnimation, ZEngine's class for ZImage based animations.
|
||||||
<br>$Id: ZE_ZAnimation.cpp,v 1.1 2003/11/25 01:31:37 cozman Exp $<br>
|
<br>$Id: ZE_ZAnimation.cpp,v 1.2 2003/12/24 04:44:41 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -25,29 +25,26 @@ namespace ZE
|
|||||||
ZAnimation::ZAnimation() :
|
ZAnimation::ZAnimation() :
|
||||||
rEngine(ZEngine::GetInstance()),
|
rEngine(ZEngine::GetInstance()),
|
||||||
rAnimImages(NULL),
|
rAnimImages(NULL),
|
||||||
rAnimWidth(0),rAnimHeight(0),
|
|
||||||
rCurFrame(0),rNumFrames(0),rFrameStep(0),
|
rCurFrame(0),rNumFrames(0),rFrameStep(0),
|
||||||
rFrameDelay(0),rNextFrameTime(0),
|
rFrameDelay(0),rNextFrameTime(0),
|
||||||
rLoop(false), rBackwards(false)
|
rAnimType(ZANIM_NONE), rBackwards(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ZAnimation::ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, bool loop, bool backwards, float width, float height)
|
ZAnimation::ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
rEngine = ZEngine::GetInstance();
|
||||||
Create(images,numFrames,frameDelay,loop,backwards,width,height);
|
Create(images,numFrames,frameDelay,type,backwards);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, bool loop, bool backwards, float width, float height)
|
void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards)
|
||||||
{
|
{
|
||||||
rAnimImages = images;
|
rAnimImages = images;
|
||||||
rNumFrames = numFrames;
|
rNumFrames = numFrames;
|
||||||
rFrameDelay = frameDelay;
|
rFrameDelay = frameDelay;
|
||||||
rLoop = loop;
|
rAnimType = type;
|
||||||
rBackwards = backwards;
|
rBackwards = backwards;
|
||||||
rAnimWidth = width;
|
Reset();
|
||||||
rAnimHeight = height;
|
|
||||||
Stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::SetAnimImages(ZImage *images, int numFrames)
|
void ZAnimation::SetAnimImages(ZImage *images, int numFrames)
|
||||||
@ -61,28 +58,25 @@ void ZAnimation::SetFrameDelay(Uint32 frameDelay)
|
|||||||
rFrameDelay = frameDelay;
|
rFrameDelay = frameDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::SetAnimType(bool loop, bool backwards)
|
void ZAnimation::SetAnimType(ZAnimType type, bool backwards)
|
||||||
{
|
{
|
||||||
rLoop = loop;
|
rAnimType = type;
|
||||||
rBackwards = backwards;
|
rBackwards = backwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::SetAnimSize(float width, float height)
|
void ZAnimation::Reset()
|
||||||
{
|
{
|
||||||
rAnimWidth = width;
|
rFrameStep = 0;
|
||||||
rAnimHeight = height;
|
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::Start()
|
void ZAnimation::Start()
|
||||||
{
|
{
|
||||||
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
if(rAnimType != ZANIM_NONE)
|
||||||
Unpause();
|
rFrameStep = rBackwards ? -1 : 1;
|
||||||
}
|
else
|
||||||
|
rFrameStep = 0;
|
||||||
void ZAnimation::Stop()
|
rNextFrameTime = rEngine->GetTime()+rFrameDelay;
|
||||||
{
|
|
||||||
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
|
||||||
Pause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::Pause()
|
void ZAnimation::Pause()
|
||||||
@ -90,12 +84,6 @@ void ZAnimation::Pause()
|
|||||||
rFrameStep = 0;
|
rFrameStep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::Unpause()
|
|
||||||
{
|
|
||||||
rFrameStep = rBackwards ? -1 : 1;
|
|
||||||
rNextFrameTime = rEngine->GetTime()+rFrameDelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZAnimation::SetFrame(int frame)
|
void ZAnimation::SetFrame(int frame)
|
||||||
{
|
{
|
||||||
if(frame >= 0 && frame < rNumFrames)
|
if(frame >= 0 && frame < rNumFrames)
|
||||||
@ -110,40 +98,49 @@ void ZAnimation::SetFrame(int frame)
|
|||||||
|
|
||||||
void ZAnimation::Update()
|
void ZAnimation::Update()
|
||||||
{
|
{
|
||||||
if(rEngine->GetTime() >= rNextFrameTime)
|
//if not paused/stopped and time to update has come
|
||||||
|
if(rFrameStep && rEngine->GetTime() >= rNextFrameTime)
|
||||||
{
|
{
|
||||||
rCurFrame += rFrameStep;
|
rCurFrame += rFrameStep;
|
||||||
|
|
||||||
if(rCurFrame < 0 || rCurFrame >= rNumFrames)
|
if(rCurFrame < 0 || rCurFrame >= rNumFrames)
|
||||||
{
|
{
|
||||||
if(rLoop)
|
switch(rAnimType)
|
||||||
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Stop();
|
case ZANIM_ONCE:
|
||||||
SetFrame(-1); //set to last frame
|
Pause();
|
||||||
|
rCurFrame = rBackwards ? 0 : rNumFrames-1;
|
||||||
|
break;
|
||||||
|
case ZANIM_LOOP:
|
||||||
|
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
||||||
|
break;
|
||||||
|
case ZANIM_REVERSE:
|
||||||
|
rBackwards = !rBackwards;
|
||||||
|
rCurFrame = rBackwards ? rNumFrames-2 : 1; //second to last or second frame
|
||||||
|
rFrameStep *= -1;
|
||||||
|
break;
|
||||||
|
case ZANIM_NONE:
|
||||||
|
default:
|
||||||
|
Reset();
|
||||||
|
//error?
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rNextFrameTime = rEngine->GetTime()+rFrameDelay;
|
rNextFrameTime = rEngine->GetTime()+rFrameDelay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAnimation::Draw(float x, float y)
|
void ZAnimation::Draw(float x, float y) const
|
||||||
{
|
{
|
||||||
if(rAnimImages)
|
if(rAnimImages)
|
||||||
{
|
|
||||||
#if (GFX_BACKEND == ZE_OGL)
|
|
||||||
rAnimImages[rCurFrame].Resize(rAnimWidth,rAnimHeight);
|
|
||||||
rAnimImages[rCurFrame].Draw(x,y);
|
rAnimImages[rCurFrame].Draw(x,y);
|
||||||
#elif (GFX_BACKEND == ZE_SDL)
|
//else
|
||||||
rAnimImages[rCurFrame].Draw(static_cast<int>(x),static_cast<int>(y));
|
//error: images not loaded
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZAnimation::Stopped()
|
bool ZAnimation::Running() const
|
||||||
{
|
{
|
||||||
return rFrameStep == 0;
|
return rFrameStep != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user