QTimeLine skips the first frame
Unsolved
Game Development
-
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?