Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QTimeLine skips the first frame

QTimeLine skips the first frame

Scheduled Pinned Locked Moved Unsolved Game Development
qtimelinerpg-gameanimation
2 Posts 2 Posters 979 Views
  • 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.
  • J Offline
    J Offline
    JaffaCakes
    wrote on last edited by
    #1

    I am making a player move across the screen using QTimeLine to handle the animation/movement in the specified time.

    In my player constructor:

    
        timeLine = new QTimeLine(500);
        timeLine->setFrameRange(1, 4);
        timeLine->setCurveShape(QTimeLine::CurveShape::LinearCurve);
        QObject::connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(animatedMove(int)));
    

    I removed the animation stuff to just show the problem:

    void PlayerSprite::animatedMove(int frame)
    {
        qDebug() << "Frame: " << frame;
    }
    

    The timer is started in a slot which is called on key press:

    void PlayerSprite::move(Direction direction)
    {
        timeLine->start();
    }
    

    The output is:

    GameView: Player is moving
    Frame:  2
    Frame:  3
    Frame:  4
    GameView: Player is moving
    Frame:  1
    Frame:  2
    Frame:  3
    Frame:  4
    

    But it should be:

    GameView: Player is moving
    Frame:  1
    Frame:  2
    Frame:  3
    Frame:  4
    GameView: Player is moving
    Frame:  1
    Frame:  2
    Frame:  3
    Frame:  4
    

    During each frame the player moves e.g. 2 steps. Therefore should move 4x2=8 steps... but on the first frame it only moves 6 steps meaning my character falls out of the game grid. I'm making an small 16 bit rpg ;)

    Is this because it is assumed that my player is already in it's first frame?
    if so can this be overridden?

    1 Reply Last reply
    0
    • tom8oeT Offline
      tom8oeT Offline
      tom8oe
      wrote on last edited by
      #2

      I think you need to set your start frame to 0 not 1.

      timeLine->setFrameRange(0, 4);
      
      1 Reply Last reply
      1

      • Login

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