If you just do deltatime = newtime-oldtime, then it will still work when it is negative.
And to handle the case where it wraps around, which I don't know will work with the above, I just have a check to see if deltatime is too great. If it's like more than 250ms, then I ignore that and recalculate the time. This solution works well for when the user tabs out of the app too.
And to handle the case where it wraps around, which I don't know will work with the above, I just have a check to see if deltatime is too great. If it's like more than 250ms, then I ignore that and recalculate the time. This solution works well for when the user tabs out of the app too.