cocos2d-x时钟小项目

cocos2d-x时钟小项目,第1张

概述项目源码:http://download.csdn.net/download/laixiao_hero/9387974 主要代码: HelloWorldScene.h文件: #ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocostudio/CocoStud

项目源码:http://download.csdn.net/download/laixiao_hero/9387974

主要代码:
HelloWorldScene.h文件:

#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocostudio/CocoStudio.h"#include "ui/CocosGUI.h"using namespace cocos2d::ui;class HelloWorld : public cocos2d::Layer{public:    // there's no 'ID' in cpp,so we recommend returning the class instance pointer    static cocos2d::Scene* createScene();    // Here's a difference. Method 'init' in cocos2d-x returns bool,instead of returning 'ID' in cocos2d-iphone    virtual bool init();    // implement the "static create()" method manually    CREATE_FUNC(HelloWorld);private:    Layout* Panel_1;    ImageVIEw* shi;    ImageVIEw* fen;    ImageVIEw* miao;    int shiR = 0; //时针旋转角度    int fenR = 0; //分针旋转角度    int miaoR = 0; //秒针旋转角度    struct tm *tm;    time_t timep;    voID changeClock(float dt);};#endif // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp文件:

#include "HelloWorldScene.h"#include "cocostudio/CocoStudio.h"#include "ui/CocosGUI.h"USING_NS_CC;using namespace cocostudio::timeline;using namespace cocos2d::ui;Scene* HelloWorld::createScene(){    // 'scene' is an autorelease object    auto scene = Scene::create();    // 'layer' is an autorelease object    auto layer = HelloWorld::create();    // add layer as a child to scene    scene->addChild(layer);    // return the scene    return scene;}// on "init" you need to initialize your instancebool HelloWorld::init(){    //////////////////////////////    // 1. super init first    if ( !Layer::init() )    {        return false;    }    auto rootNode = csloader::createNode("MainScene.csb");    Panel_1 = (cocos2d::ui::Layout*)rootNode->getChildByname("Panel_1");    shi = (ImageVIEw*)Helper::seekWidgetByname(Panel_1,"shi");    fen = (ImageVIEw*)Helper::seekWidgetByname(Panel_1,"fen");    miao = (ImageVIEw*)Helper::seekWidgetByname(Panel_1,"miao");    Vec2 visiableSize = Director::getInstance()->getVisibleSize();    Panel_1->setAnchorPoint(Vec2(0.5,0.5));    Panel_1->setposition(Vec2(visiableSize.x/2,visiableSize.y/2));    this->schedule(schedule_selector(HelloWorld::changeClock),1.0f);    addChild(rootNode);    return true;}voID HelloWorld::changeClock(float dt){    if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) {        time(&timep);    }    else {        struct timeval NowTimeval;        gettimeofday(&NowTimeval,NulL);        timep = NowTimeval.tv_sec;    }    tm = localtime(&timep);    int year = tm->tm_year + 1900;    int month = tm->tm_mon + 1;    int day = tm->tm_mday;    int hour = tm->tm_hour;    int min = tm->tm_min;    int second = tm->tm_sec;    miaoR = second * 6;    fenR = min * 6;    if (hour>12) {        shiR = (hour - 12) * 5 * 6 + (fenR / 72) * 6;//转换成12时制,方便计算。    }    else    {        shiR = hour * 5 * 6 + (fenR / 72) * 6;    }    shi->setRotation(shiR);    fen->setRotation(fenR);    miao->setRotation(miaoR);    cclOG("%d-%d-%d %d-%d-%d",year,month,day,hour,min,second);//输出时间2015-12-30 14-47-8}
总结

以上是内存溢出为你收集整理的cocos2d-x时钟小项目全部内容,希望文章能够帮你解决cocos2d-x时钟小项目所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1076256.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存