Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why isnt my state transition animation triggered automatically?
Qt 6.11 is out! See what's new in the release blog

Why isnt my state transition animation triggered automatically?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 116 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mbkerdellou
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved