QTimer setInterval without resetting the remaining time

I have an application written in QT that uses QTimer. This is basically a game, and all actions are controlled by a timer. The game includes the ability to increase / decrease the speed of the game. Code to increase speed:

    timerValue -= speedUpValue;
    if (timerValue < maxSpeed) {
        timerValue = maxSpeed;
    }
    timer -> setInterval(timerValue); 

speedUpValueand maxSpeedare constants. Almost the same code is used to reduce speed. The problem is that it setIntervalresets the internal timer, and therefore, if you constantly increase or decrease the speed, the game will never continue as a result, because the remainingTimereset is constantly on. Is there a way to set remainingTimemanually or change the interval without restarting it?

+4
source share
1

QTimer::singleShot(...) timerValue. , timerValue, .

RA, , , setInterval() , , , , - .

, , , . , , , , , .

, , . , , . , , , , , , , .

+3

Source: https://habr.com/ru/post/1610056/


All Articles