下面介绍如何在cocos2dx中实现一个时钟的功能。
其实实现很简单,获取到当前的时间,然后添加一个定时器,每隔一秒计时加一秒。
下面给出代码实现:
int nHour;
int nMinute;
int nSecond;
nHour = 0;
nMinute = 0;
nSecond = 0;
struct cc_timeval now;
CCTime::gettimeofdayCocos2d(&now, NULL);
struct tm* tm;
tm = localtime(&now.tv_sec);
nHour = tm->tm_hour;
nMinute = tm->tm_min;
nSecond = tm->tm_sec;
CCLog("%d -- %d -- %d",nHour,nMinute,nSecond);
this-&g