Cocos2d NSDate analogue in Cocos2d-x

Cocos2d NSDate analogue in Cocos2d-x
0.0 0


I’m porting from obj-c to cocos2d-x code from - full sample project.
I’m stuck with the following code:

-(void)gameLogic:(ccTime)dt {

static double lastTimeTargetAdded = 0;
double now = [[NSDate date] timeIntervalSince1970];
Cocos2DSimpleGameAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
if(lastTimeTargetAdded == 0 || now - lastTimeTargetAdded >= delegate.curLevel.spawnRate) {
[self addTarget];
lastTimeTargetAdded = now;


I can’t NSDate analogue in cocos2d-x: there is no CCDate in cocos2d-x, ccTime does not have any methods (it’s float typedef) and no date.h in stlport. What I’m supposed to do? I’m new to cocos2d-x, so help me! I can try to write some variable and increment it in sheduled methods, but I want to see some realisation of Date class and don’t create a wheel.


Hes using some weird stuff to keep track of the times the enemies are added. You can simply save the staring time and then in the update compare it to ccTime dt to know how much time has passed.


Finally I was able to achieve features of NSDate in cocos2d-x
CCTime does this for you,all I did is included “Platform.h” file and wrote the code posted below

#include “platform.h”

cc_timeval startTime=new cc_timeval;
endTime=new cc_timeval;
double duration=CCTime::timersubCocos2d(startTime,endTime);
delete startTime;
delete endTime;