The CACurrentMediaTime() function exists in Cocos2dx?

Hello everyone

I’ve seen some tutorials on Objective-C. They use CACurrentMediaTime function to build the examples.
I not find this function in Cocos2dx.

Anyone know another alternative for this function?

Thanks and regards

@Solidux

Here is the method to calculate the delta time between frames, hope it can inspire your.

void Director::calculateDeltaTime()
{
 struct timeval now;
   if (gettimeofday(&now, nullptr) != 0)
   {
        CCLOG("error in gettimeofday");
        _deltaTime = 0;
        return;
    }
    if (_nextDeltaTimeZero)
    {
        _deltaTime = 0;
        _nextDeltaTimeZero = false;
    }
    else
    {
        _deltaTime = (now.tv_sec - _lastUpdate->tv_sec) + (now.tv_usec - _lastUpdate->tv_usec) / 1000000.0f;
        _deltaTime = MAX(0, _deltaTime);
    }
    *_lastUpdate = now;
}

Thanks for the tip.
I implemented your solution and going well :slight_smile:
I also found this function CCDirector::sharedDirector()->getDeltaTime().
Calculate the same value of your function :slight_smile:
Just one more question. This calculated value is the same as the function CACurrentMediaTime()?

Thank you very much.
Regards

@Solidux

Here is the description of CACurrentMediaTime:

CACurrentMediaTime
Returns the current absolute time, in seconds.

CFTimeInterval CACurrentMediaTime (void);

As I know, the gettimeofday is a C function which returns the current system time in miniseconds.

I think they might be more or less the same. But I’m not sure.:slight_smile: