What just happened?

We introduced a NumberAnimation element that is set to animate the x property of the sun object. The animation starts at 0 and lasts until x reaches the root item's width (which is the right edge of the scene). The movement lasts for dayLength milliseconds. The running property of the animation is set to true to enable the animation. Since we didn't specify otherwise, the motion is linear.

You may be thinking that the animation runs in the wrong direction—"west" is on the left and "east" is on the right, yes? That's true, however, only if the observer faces north. If that were the case for our scene, we wouldn't be seeing the sun at all—at noon, it crosses the south direction.

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.