The next thing we want to do is make our elephant movable. In order to achieve that, we add a QTimer m_timer private member to MyScene. QTimer is a class that can emit the timeout() signal periodically with the given interval. In the MyScene constructor, we set up the timer with the following code:
m_timer.setInterval(30); connect(&m_timer, &QTimer::timeout, this, &MyScene::movePlayer);
First, we define that the timer emits the timeout signal every 30 milliseconds. Then, we connect that signal to the scene's slot called movePlayer(), but we do not start the timer yet. The timer will be started when the player presses a key to move.
Next, we need to handle the input events properly and update the player's ...