Answer the question
In order to leave comments, you need to log in
How to properly write a game loop in QML?
For some reason, I can't link the object's movement to the time it took to calculate the movement. I took the game loop from the Habré example - the latest one, with all the goodies in the form of interpolation and prediction =)
Instead of while( game_is_running ) { /*code*/ } I put Timer { onTriggered: { /*code*/ }}
This is what happened: pastebin ( pastie )
Frankly, it turned out to be complete garbage! The ball does not fall smoothly, but with smooth twitches =) as if someone from below is blowing on it with different force.
Also, as I assumed, such a cycle would have to draw the state of the object in the same way, regardless of the interval. But this is not true at all. If the timer interval is not 10, but 1, then the ball falls much faster. Why? After all, there is a limitation on personnel, so why does its state change differently than it is written in the article? I don't understand.
Does it even make sense to make the game loop like this? Or can you get by with a regular timer? How to correctly calculate the position of an object depending on time?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question