ZAnimation
This commit is contained in:
parent
f8abcedf18
commit
96680b22a0
75
include/ZE_ZAnimation.h
Normal file
75
include/ZE_ZAnimation.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
This file is Part of the ZEngine Library for 2D game development.
|
||||||
|
Copyright (C) 2002, 2003 James Turk
|
||||||
|
|
||||||
|
Licensed under a BSD-style license.
|
||||||
|
|
||||||
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
||||||
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\file ZE_ZAnimation.h
|
||||||
|
\brief Definition file for ZAnimation.
|
||||||
|
|
||||||
|
Definition file for ZAnimation, a class for animations using ZImage.
|
||||||
|
<br>$Id: ZE_ZAnimation.h,v 1.1 2003/11/25 01:31:36 cozman Exp $<br>
|
||||||
|
\author James Turk
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef __ze_zanimation_h__
|
||||||
|
#define __ze_zanimation_h__
|
||||||
|
|
||||||
|
#include "ZE_ZEngine.h"
|
||||||
|
#include "ZE_ZImage.h"
|
||||||
|
|
||||||
|
namespace ZE
|
||||||
|
{
|
||||||
|
|
||||||
|
enum ZAnimationType
|
||||||
|
{
|
||||||
|
ZANIM_ONCE,
|
||||||
|
ZANIM_LOOP,
|
||||||
|
ZANIM_REV_ONCE,
|
||||||
|
ZANIM_REV_LOOP
|
||||||
|
};
|
||||||
|
|
||||||
|
class ZAnimation
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
ZEngine *rEngine;
|
||||||
|
ZImage *rAnimImages;
|
||||||
|
float rAnimWidth;
|
||||||
|
float rAnimHeight;
|
||||||
|
int rCurFrame;
|
||||||
|
int rNumFrames;
|
||||||
|
int rFrameStep;
|
||||||
|
Uint32 rFrameDelay;
|
||||||
|
Uint32 rNextFrameTime;
|
||||||
|
bool rLoop;
|
||||||
|
bool rBackwards;
|
||||||
|
public:
|
||||||
|
ZAnimation();
|
||||||
|
ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, bool loop=false, bool backwards=false, float width=0, float height=0);
|
||||||
|
|
||||||
|
void Create(ZImage *images, int numFrames, Uint32 frameDelay, bool loop=false, bool backwards=false, float width=0, float height=0);
|
||||||
|
void SetAnimImages(ZImage *images, int numFrames);
|
||||||
|
void SetFrameDelay(Uint32 frameDelay);
|
||||||
|
void SetAnimType(bool loop, bool backwards);
|
||||||
|
void SetAnimSize(float width, float height);
|
||||||
|
|
||||||
|
void Start();
|
||||||
|
void Stop();
|
||||||
|
void Pause();
|
||||||
|
void Unpause();
|
||||||
|
void SetFrame(int frame);
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
void Draw(float x, float y);
|
||||||
|
|
||||||
|
bool Stopped();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //__ze_zanimation_h__
|
149
src/ZE_ZAnimation.cpp
Normal file
149
src/ZE_ZAnimation.cpp
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
This file is Part of the ZEngine Library for 2D game development.
|
||||||
|
Copyright (C) 2002, 2003 James Turk
|
||||||
|
|
||||||
|
Licensed under a BSD-style license.
|
||||||
|
|
||||||
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
||||||
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file ZE_ZAnimation.cpp
|
||||||
|
\brief Source file for ZAnimation.
|
||||||
|
|
||||||
|
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>
|
||||||
|
\author James Turk
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "ZE_ZAnimation.h"
|
||||||
|
|
||||||
|
namespace ZE
|
||||||
|
{
|
||||||
|
|
||||||
|
ZAnimation::ZAnimation() :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rAnimImages(NULL),
|
||||||
|
rAnimWidth(0),rAnimHeight(0),
|
||||||
|
rCurFrame(0),rNumFrames(0),rFrameStep(0),
|
||||||
|
rFrameDelay(0),rNextFrameTime(0),
|
||||||
|
rLoop(false), rBackwards(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ZAnimation::ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, bool loop, bool backwards, float width, float height)
|
||||||
|
{
|
||||||
|
rEngine = ZEngine::GetInstance();
|
||||||
|
Create(images,numFrames,frameDelay,loop,backwards,width,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, bool loop, bool backwards, float width, float height)
|
||||||
|
{
|
||||||
|
rAnimImages = images;
|
||||||
|
rNumFrames = numFrames;
|
||||||
|
rFrameDelay = frameDelay;
|
||||||
|
rLoop = loop;
|
||||||
|
rBackwards = backwards;
|
||||||
|
rAnimWidth = width;
|
||||||
|
rAnimHeight = height;
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::SetAnimImages(ZImage *images, int numFrames)
|
||||||
|
{
|
||||||
|
rAnimImages = images;
|
||||||
|
rNumFrames = numFrames;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::SetFrameDelay(Uint32 frameDelay)
|
||||||
|
{
|
||||||
|
rFrameDelay = frameDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::SetAnimType(bool loop, bool backwards)
|
||||||
|
{
|
||||||
|
rLoop = loop;
|
||||||
|
rBackwards = backwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::SetAnimSize(float width, float height)
|
||||||
|
{
|
||||||
|
rAnimWidth = width;
|
||||||
|
rAnimHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Start()
|
||||||
|
{
|
||||||
|
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
||||||
|
Unpause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Stop()
|
||||||
|
{
|
||||||
|
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
||||||
|
Pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Pause()
|
||||||
|
{
|
||||||
|
rFrameStep = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Unpause()
|
||||||
|
{
|
||||||
|
rFrameStep = rBackwards ? -1 : 1;
|
||||||
|
rNextFrameTime = rEngine->GetTime()+rFrameDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::SetFrame(int frame)
|
||||||
|
{
|
||||||
|
if(frame >= 0 && frame < rNumFrames)
|
||||||
|
rCurFrame = frame;
|
||||||
|
else if(frame < 0 && frame >= -rNumFrames)
|
||||||
|
SetFrame(rNumFrames+frame);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//invalid frame
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Update()
|
||||||
|
{
|
||||||
|
if(rEngine->GetTime() >= rNextFrameTime)
|
||||||
|
{
|
||||||
|
rCurFrame += rFrameStep;
|
||||||
|
|
||||||
|
if(rCurFrame < 0 || rCurFrame >= rNumFrames)
|
||||||
|
{
|
||||||
|
if(rLoop)
|
||||||
|
rCurFrame = rBackwards ? rNumFrames-1 : 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
SetFrame(-1); //set to last frame
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rNextFrameTime = rEngine->GetTime()+rFrameDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZAnimation::Draw(float x, float y)
|
||||||
|
{
|
||||||
|
if(rAnimImages)
|
||||||
|
{
|
||||||
|
#if (GFX_BACKEND == ZE_OGL)
|
||||||
|
rAnimImages[rCurFrame].Resize(rAnimWidth,rAnimHeight);
|
||||||
|
rAnimImages[rCurFrame].Draw(x,y);
|
||||||
|
#elif (GFX_BACKEND == ZE_SDL)
|
||||||
|
rAnimImages[rCurFrame].Draw(static_cast<int>(x),static_cast<int>(y));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZAnimation::Stopped()
|
||||||
|
{
|
||||||
|
return rFrameStep == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -61,6 +61,9 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath="..\src\ZE_Utility.cpp">
|
RelativePath="..\src\ZE_Utility.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\ZE_ZAnimation.cpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\ZE_ZConfigFile.cpp">
|
RelativePath="..\src\ZE_ZConfigFile.cpp">
|
||||||
</File>
|
</File>
|
||||||
@ -104,6 +107,9 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath="..\include\ZE_Utility.h">
|
RelativePath="..\include\ZE_Utility.h">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\include\ZE_ZAnimation.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\include\ZE_ZBaseParticleSystem.h">
|
RelativePath="..\include\ZE_ZBaseParticleSystem.h">
|
||||||
</File>
|
</File>
|
||||||
|
Loading…
Reference in New Issue
Block a user