cocos2d-x之闹钟篇

来源:互联网 发布:淘宝制作宝贝详情步骤 编辑:程序博客网 时间:2024/06/16 19:00

这几天不忙,终于可以学习了 写了个闹钟 跟大家分享下


    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);

    CCLog("%d %d %d",tm->tm_mday,tm->tm_mon+1,tm->tm_year +1900);

    CCLog("星期%d 本年的第%d 是否开夏令时%d",tm->tm_wday,tm->tm_yday+1,tm->tm_isdst);

    CCLog("%ld 当前时区的名字%s",tm->tm_gmtoff,tm->tm_zone);

    this->schedule(schedule_selector(HelloWorld::timeUpdate), 1);



void HelloWorld::timeUpdate(){

    

    CCSprite * miaozhen = (CCSprite *)getChildByTag(miaozhen_tag);

    CCSprite * shizhen = (CCSprite *)getChildByTag(shizhen_tag);

    CCSprite * fenzhen = (CCSprite *)getChildByTag(fenzhen_tag);

    nSecond++;

    if (nSecond==60) {

        nSecond = 0;

        nMinute++;

        if (nMinute == 60) {

            nMinute = 0;

            nHour++;

            if (nHour== 24) {

                nHour = 0;

            }

        }

    }

    int ss = nHour;

    if (ss>=12) {

        ss = nHour - 12;

    }

    shizhen->setRotation(CC_RADIANS_TO_DEGREES(ss*1.0/12*2*3.14)-90);

    fenzhen->setRotation(CC_RADIANS_TO_DEGREES((nMinute+1)*1.0/60*2*3.14)- 15);

    miaozhen->setRotation(CC_RADIANS_TO_DEGREES((nSecond+1)*1.0/60*2*3.14)- 15);

    

    CCLog("%d -- %d -- %d",nHour,nMinute,nSecond);

}


效果图"




0 0
原创粉丝点击