Why isnt my state transition animation triggered automatically?
-
I am trying to understand the state machine system of qt, i have this simple machine
void CharacterItem::setupStateMachine() { m_moveStateMachine = new QStateMachine(); QState* idleState = new QState(m_moveStateMachine); QState* movingState = new QState(m_moveStateMachine); std::vector<QPixmap> movingFrames = SpriteManager::GetAnimationFrames( SpriteManager::AnimationType::Walk); CharacterAnimation* movingAnimation = new CharacterAnimation(movingFrames); QSignalTransition* idleToMovingTransition = idleState->addTransition(this, &CharacterItem::startMovingAnimation, movingState); connect(movingState, &QState::entered, []() { qDebug() << "entered"; }); idleToMovingTransition->addAnimation(movingAnimation); m_moveStateMachine->setInitialState(idleState); m_moveStateMachine->start(); }and my Character Animation class :
void CharacterAnimation::updateCurrentTime(int currentTime) { qDebug() << currentTime; m_currentTime = currentTime; } CharacterAnimation::CharacterAnimation(std::vector<QPixmap> frames, QObject* parent) : m_frames{frames} , QAbstractAnimation{parent} {} int CharacterAnimation::duration() const { return m_duration; } void CharacterAnimation::setDuration(int duration) { m_duration = duration; }I am emitting the animation starting signal on click just to test it, the state transition happens but the animation doesn't as updateCurrentTime isn't printing anything. If I set the animation manually to start by doing movingAnimation->start(); it actually prints numbers from 0 to 1000 ( my default duration).
I thought the animation starts automatically?
I would appreciate your help, thanks
-
Hi,
Might be a silly question but how do you determine that your animation is not working ?
The code snippet you provide seems correct however there's not enough code at lease for CharacterAnimation to ensure it's not working.Can you share minimal compilable example that reproduces the behaviour you get ?