Cocos2d-x 实现时钟
来源:互联网 发布:美微网络电视看香蕉 编辑:程序博客网 时间:2024/05/19 02:23
下面介绍如何在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->schedule(schedule_selector(HelloWorld::timeUpdate), 1);
void HelloWorld::timeUpdate(){ nSecond++; if (nSecond==60) { nSecond = 0; nMinute++; if (nMinute == 60) { nMinute = 0; nHour++; if (nHour==24) { nHour = 0; } } } CCLog("%d -- %d -- %d",nHour,nMinute,nSecond);}
struct tm {inttm_sec;/* seconds after the minute [0-60] */inttm_min;/* minutes after the hour [0-59] */inttm_hour;/* hours since midnight [0-23] */inttm_mday;/* day of the month [1-31] */inttm_mon;/* months since January [0-11] */inttm_year;/* years since 1900 */inttm_wday;/* days since Sunday [0-6] */inttm_yday;/* days since January 1 [0-365] */inttm_isdst;/* Daylight Savings Time flag */longtm_gmtoff;/* offset from CUT in seconds */char*tm_zone;/* timezone abbreviation */};
运行上面的代码看看:
Cocos2d: 19 -- 9 -- 27
Cocos2d: 19 -- 9 -- 28
Cocos2d: 19 -- 9 -- 29
Cocos2d: 19 -- 9 -- 30
Cocos2d: 19 -- 9 -- 31
Cocos2d: 19 -- 9 -- 32
Cocos2d: 19 -- 9 -- 33
每隔一秒就输出当前的时间: 19点09分**秒- Cocos2d-x 实现时钟
- Cocos2d-x教程(2)-制作时钟
- Cocos2d-x教程(2)-制作时钟
- 20.cocos2d-x时钟小项目
- [COCOS2D-X]裁剪实现
- cocos2d-x音效实现
- COCOS2D-X]裁剪实现
- cocos2d-x 画笔实现
- cocos2d-x 进度条的实现
- cocos2d-x CCAnimation实现动画
- cocos2d-x 滚动条实现
- 实现 Cocos2d-x 全局定时器
- 实现 Cocos2d-x 全局定时器
- Cocos2d-x 实现委托机制
- Cocos2d-x CCTableView实现列表
- cocos2d-x实现滑屏
- cocos2d-x实现列表滑动
- cocos2d-x进度条的实现
- visual studio 2012 express 全序列号
- Google Analytics(谷歌分析) 架构与原理
- 避免创建不必要的对象
- 网络报文中流的处理
- TCP连接探测中的Keepalive和心跳包. 关键字: tcp keepalive, 心跳, 保活
- Cocos2d-x 实现时钟
- 霍夫变换(Hough Transform)直线检测
- Eclipse中快捷键
- HDU 1166(敌兵布阵)
- 设计模式之命令模式,command
- UISwitch
- Salesforce travel
- JS 将 格式化的时间 转换成 时间戳
- 安装vs2010 MSDN