Hi Todd,
Isak is of course right, your Timer is running but never stops. With QML you have several options of stopping the timer. You could make a so called property binding on the running property of the Timer, like Isak suggested. If you don’t know what a property binding is, please quickly go through our getting started tutorial (there is also a video available).
Timer {
running: gameScene.gameIsRunning
// ... more stuff
}
The gameIsRunning property is already available if you look at the GameScene.qml file. By the way, I would also suggest to put your Timer there instead of the Numbers.qml, as the timer is more game logic related and the Numbers.qml is only used to display a number.
The other possibility is to set the running property of the Timer to false initially, and call distancetimer.start() and distancetimer.stop() manually, e.g. in the startGame() and stopGame() functions of the GameScene.qml. This is again easier if the Timer is part of the GameScene.qml, as you don’t need to make aliases or similar then. This topic is also covered in the getting started tutorial.
And one last detail that I want to add: You are triggering the timer every millisecond, which is creating a minor overhead. As your game is running at 60FPS, a new frame is rendered 60 times per second, which is about once every 17 millisecond. Any change between the frames won’t be visible immediately, until the next frame is rendered 17milliseconds later. So there is no real reason to trigger the timer 17 times in this time frame, instead of once every 17 milliseconds. If you change the interval property of your timer to 17 (and then maybe increase the score by more than 1 to compensate), you are getting a minor performance improvement, as you eliminate 16/17 timer triggers by getting the same results. This won’t be visible in your small project, but it can have an impact in larger ones. I wanted to mention it anyway, since this forum is also a knowledge base to other users as well right 🙂
Cheers,
Alex