#include "actor.h" #include "animationmanager.h" #include #include #include #define SPRITE_MARGIN 2 #define SPRITE_PLAYER_WIDTH 16 #define SPRITE_PLAYER_HEIGHT 16 static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) { return (progress == 1.0) ? end : start; } Actor::Actor(Type type) : m_type(type), m_direction(Actor::None) { m_pix = ":/" + QString("actor%1").arg(type); setPixmap(m_pix); setSprite(82, 82, 16, 16); m_direction = Actor::Left; qRegisterAnimationInterpolator(myBooleanInterpolator); QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this); group->setLoopCount(-1); for (int i = 0; i < 4; i++) { PixmapItem *step = new PixmapItem(m_pix, this); int x = i * 20 + SPRITE_MARGIN; int y = m_direction * 20 + SPRITE_MARGIN; step->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); step->setVisible(false); QPropertyAnimation *anim = new QPropertyAnimation(step, "visible", group); anim->setDuration(0); anim->setEndValue(true); group->addPause(100); QPropertyAnimation *anim2 = new QPropertyAnimation(step, "visible", group); anim2->setDuration(0); anim2->setEndValue(false); } AnimationManager::self()->registerAnimation(group); group->start(); }