zoukankan      html  css  js  c++  java
  • 制作时钟cocos3.0

    clockBackgroundScene.h头文件:

    #ifndef __Clock_1__clockBackgroundScene__
    #define __Clock_1__clockBackgroundScene__
    
    #include <iostream>
    #include "cocos2d.h"
    USING_NS_CC;
    class clockBackground: public Layer
    {
    public:
        virtual bool init();
        static cocos2d::Scene * scene();         
        CREATE_FUNC(clockBackground);
        void MutUpdate(float dt);
    public:
        Sprite * m_hour;       
        Sprite * m_minute;
        Sprite * m_second;
    	int mRotation;
    	int sRotation;
    	int hRotation;
    private:
        int nHour;     
        int nMinute;
        int nSecond;
    	 
    
    };
    #endif 
    

    clockbackgroundScene.cpp文件:

    #include "clockBackgroundScene.h"
    
    Scene * clockBackground::scene(){
    	Scene * scene = Scene::create();
    	clockBackground * layer = clockBackground::create();
    	scene->addChild(layer);
    	return scene;
    }
    
    bool clockBackground::init(){
    	Size winSize = Director::getInstance()->getVisibleSize();
    	Sprite * clockBk = Sprite::create("background.jpg");
    	clockBk->setPosition(ccp(winSize.width / 2, winSize.height / 2));
    	clockBk->setScale(0.5f);
    
    	this->addChild(clockBk);
    
    
    	
    	m_minute = Sprite::create("fen.png");
    	m_minute->setAnchorPoint(ccp(0, 0.5));
    	m_minute->setScale(0.2f);
    	m_minute->setRotation(-90);
    	m_minute->setPosition(ccp(winSize.width / 2, winSize.height / 2));
    	this->addChild(m_minute);
    
    	
    	m_second = Sprite::create("miao.png");
    	m_second->setAnchorPoint(ccp(0, 0.5));
    	m_second->setScale(0.2f);
    	m_second->setRotation(-90);
    	m_second->setPosition(ccp(winSize.width / 2, winSize.height / 2));
    	this->addChild(m_second);
    	
    	m_hour = Sprite::create("shi.png");
    	m_hour->setAnchorPoint(ccp(0, 0.5));
    	m_hour->setScale(0.2f);
    	m_hour->setRotation(-90);
    	m_hour->setPosition(ccp(winSize.width / 2, winSize.height / 2));
    	this->addChild(m_hour);
    
    	///////////////获取系统当前时间
    	struct tm *tm;
    	time_t timep;
    	time(&timep);
    	tm = localtime(&timep);
    	//int year = tm->tm_year + 1900;
    	//int month = tm->tm_mon + 1;
    	//int day = tm->tm_mday;
    	nHour = tm->tm_hour;
    	nMinute = tm->tm_min;
    	nSecond = tm->tm_sec;
    	log("%d-%d-%d", nHour, nMinute, nSecond);
    	/////////////
    	mRotation = nMinute * 5 - 90;//nMinute;
    	sRotation = nSecond * 5 - 90;// nSecond;
    	hRotation = -nHour - 90;// nHour + 80;
    
    	this->schedule(schedule_selector(clockBackground::MutUpdate), 1);
    
    	return true;
    }
    void clockBackground::MutUpdate(float dt){
    
    
    	//static int mRotation = nMinute;//*6*/
    	//static int sRotation = nSecond;//static 静态变量
    
    	//static int hRotation=nHour;
    	if (nHour > 12){
    		//hRotatio = (nHour - 12) * 5 * 6 + (mRotation / 72) * 6;
    
    	}
    	else{
    		//hRotatio = (nHour)* 5 * 6 + (mRotation / 72) * 6;
    	}
    
    	m_second->setRotation(sRotation);
    
    	//m_second->runAction(RotateBy::create(sRotation,360));
    	m_minute->setRotation(mRotation);
    	m_hour->setRotation(hRotation);
    	//log("%d", sRotation);
    	if (sRotation >= 360){
    		sRotation = 0;
    		mRotation += 6;
    		m_minute->setRotation(mRotation);
    		if (mRotation % 72 == 0){//mRotation % 72 == 0
    			hRotation += 6;//6
    			m_hour->setRotation(hRotation);
    			if (mRotation >= 360){
    				mRotation = 0;
    			}
    		}
    	}
    	sRotation += 6;
    	//hRotation += 6;
    }


  • 相关阅读:
    安装Eclipse for MAC 苹果版
    visual studio code emmet 插件不提示?解决方案
    支付宝付款页面调整屏幕亮度
    浅谈iOS需要掌握的技术点
    Objective-C 编程艺术 (Zen and the Art of the Objective-C Craftsmanship 中文翻译)
    ios开发数据库版本迁移手动更新迭代和自动更新迭代艺术(-)
    ios 添加到cell 上的button点击无效!扩大button的点击区域(黑魔法)
    个人中心模块-拍照剪裁上传
    利用js与java交互
    显示gif动画(帧动画的播放)
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091766.html
Copyright © 2011-2022 走看看