Timing
Before we can move the bee and the clouds, we need to consider timing. As we already know, the main game loop executes repeatedly until the player presses the Escape key.
We have also learned that C++ and SFML are exceptionally fast. In fact, my modest laptop executes a simple game loop (like the current one) at around five thousand times per second. With this in mind, let’s discuss the problem of making the rate at which each frame of animation is shown consistent and predetermined.
The frame rate problem
Let’s consider the speed of the bee. For discussion, we could pretend that we are going to move it at 200 pixels per second. On a screen that is 1920 pixels wide, it would take, approximately, 10 seconds to cross the entire width, because 10 x 200 is 2000 (near enough to 1920).
Furthermore, we know that we can position any of our sprites with setPosition(...,...)
. We just need to put the x and y coordinates in the parentheses.
In addition...