2013-06-02 15:08:32 +00:00
|
|
|
#include "AnimationComponent.h"
|
2012-10-17 17:15:58 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
AnimationComponent::AnimationComponent()
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
|
|
|
mMoveX = 0;
|
|
|
|
mMoveY = 0;
|
|
|
|
mMoveSpeed = 0;
|
|
|
|
mFadeRate = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::move(int x, int y, int speed)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
|
|
|
mMoveX = x;
|
|
|
|
mMoveY = y;
|
|
|
|
mMoveSpeed = speed;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::fadeIn(int time)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mOpacity = 0;
|
2012-10-17 17:15:58 +00:00
|
|
|
setChildrenOpacity(0);
|
|
|
|
|
|
|
|
mFadeRate = time;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::fadeOut(int time)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mOpacity = 255;
|
2012-10-17 17:15:58 +00:00
|
|
|
setChildrenOpacity(255);
|
|
|
|
|
|
|
|
mFadeRate = -time;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::update(int deltaTime)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-05-13 19:53:28 +00:00
|
|
|
float mult = deltaTime * 0.05f;
|
2012-10-17 17:15:58 +00:00
|
|
|
|
|
|
|
if(mMoveX != 0 || mMoveY != 0)
|
|
|
|
{
|
|
|
|
int offsetx = (mMoveX > mMoveSpeed) ? mMoveSpeed : mMoveX;
|
|
|
|
int offsety = (mMoveY > mMoveSpeed) ? mMoveSpeed : mMoveY;
|
|
|
|
|
2013-05-13 19:53:28 +00:00
|
|
|
offsetx = (int)(offsetx * mult);
|
|
|
|
offsety = (int)(offsety * mult);
|
2012-10-17 17:15:58 +00:00
|
|
|
|
|
|
|
moveChildren(offsetx, offsety);
|
|
|
|
|
|
|
|
mMoveX -= offsetx;
|
|
|
|
mMoveY -= offsety;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mFadeRate != 0)
|
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
int opacity = (int)mOpacity + mFadeRate;
|
2012-10-17 17:15:58 +00:00
|
|
|
if(opacity > 255)
|
|
|
|
{
|
|
|
|
mFadeRate = 0;
|
|
|
|
opacity = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opacity < 0)
|
|
|
|
{
|
|
|
|
mFadeRate = 0;
|
|
|
|
opacity = 0;
|
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
mOpacity = (unsigned char)opacity;
|
2012-10-17 17:15:58 +00:00
|
|
|
setChildrenOpacity((unsigned char)opacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::addChild(ImageComponent* gui)
|
2013-04-08 16:52:40 +00:00
|
|
|
{
|
|
|
|
mChildren.push_back(gui);
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::moveChildren(int offsetx, int offsety)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
Vector2i move(offsetx, offsety);
|
2013-04-08 16:52:40 +00:00
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
ImageComponent* comp = mChildren.at(i);
|
|
|
|
comp->setOffset(comp->getOffset() + move);
|
2012-10-17 17:15:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void AnimationComponent::setChildrenOpacity(unsigned char opacity)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
2012-10-17 17:15:58 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
mChildren.at(i)->setOpacity(opacity);
|
2012-10-17 17:15:58 +00:00
|
|
|
}
|
|
|
|
}
|