Created
June 25, 2014 11:59
-
-
Save sdkfz181tiger/a6a514530522fb98e2f7 to your computer and use it in GitHub Desktop.
CalendarSprite(Cocos2dx_ver3.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CalendarSprite.cpp | |
// Oyadius3 | |
// | |
// Created by Shimeji Ozaki on 2014-06-22. | |
// | |
// | |
#include "CalendarSprite.h" | |
CalendarSprite::CalendarSprite(float posX, float posY, | |
float vX, float vY):BaseSprite(posX, posY, vX, vY){ | |
} | |
CalendarSprite::~CalendarSprite(){ | |
} | |
CalendarSprite* CalendarSprite::create(float posX, float posY, | |
float vX, float vY){ | |
CalendarSprite* sprite = new CalendarSprite(posX, posY, vX, vY); | |
if(sprite && sprite->initWithSpriteFrameName("space_25.png")){ | |
sprite->autorelease(); | |
sprite->setPosition(Point(posX, posY)); | |
sprite->makeStage(); | |
return sprite; | |
} | |
CC_SAFE_DELETE(sprite); | |
return NULL; | |
} | |
// makeStage | |
void CalendarSprite::makeStage(){ | |
float centerY = this->boundingBox().size.width * 0.5f; | |
myLabel = CCLabelBMFont::create("0000/00/00_00:00:00", "MisakiGothic.fnt"); | |
myLabel->setColor(Color3B(255, 255, 255)); | |
myLabel->setPosition(Point(centerY, this->boundingBox().size.height/2)); | |
this->addChild(myLabel); | |
} | |
// updateView | |
void CalendarSprite::updateView(){ | |
time_t tNow = time(NULL); | |
struct tm* lNow = localtime(&tNow); | |
this->sec = lNow->tm_sec; | |
this->min = lNow->tm_min; | |
this->hour = lNow->tm_hour; | |
this->mday = lNow->tm_mday; | |
this->mon = lNow->tm_mon + 1; | |
this->year = lNow->tm_year + 1700; | |
char cn[20]; | |
sprintf(cn, "%04d/%02d/%02d_%02d:%02d:%02d", | |
year, mon, mday, hour, min, sec); | |
myLabel->setString(cn); | |
} | |
void CalendarSprite::updateView(int year, int mon, int mday, | |
int hour, int min, int sec){ | |
this->sec = sec; | |
this->min = min; | |
this->hour = hour; | |
this->mday = mday; | |
this->mon = mon; | |
this->year = year; | |
char cn[20]; | |
sprintf(cn, "%04d/%02d/%02d_%02d:%02d:%02d", | |
year, mon, mday, hour, min, sec); | |
myLabel->setString(cn); | |
} | |
void CalendarSprite::updateView(int year, int mon, int mday){ | |
this->mday = mday; | |
this->mon = mon; | |
this->year = year; | |
char cn[20]; | |
sprintf(cn, "%04d/%02d/%02d", year, mon, mday); | |
myLabel->setString(cn); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CalendarSprite.h | |
// Oyadius3 | |
// | |
// Created by Shimeji Ozaki on 2014-06-22. | |
// | |
// | |
#ifndef __Oyadius3__CalendarSprite__ | |
#define __Oyadius3__CalendarSprite__ | |
#include "ClockSprite.h" | |
USING_NS_CC; | |
class CalendarSprite:public BaseSprite{ | |
private: | |
int sec; | |
int min; | |
int hour; | |
int mday; | |
int mon; | |
int year; | |
LabelBMFont* myLabel; | |
public: | |
CalendarSprite(){}; | |
CalendarSprite(float posX, float posY, float vX, float vY); | |
~CalendarSprite(); | |
static CalendarSprite* create(float posX, float posY, | |
float vX, float vY); | |
// makeStage | |
virtual void makeStage(); | |
// updateView | |
void updateView(); | |
void updateView(int year, int mon, int mday, | |
int hour, int min, int sec); | |
void updateView(int year, int mon, int mday); | |
}; | |
#endif /* defined(__Oyadius3__CalendarSprite__) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment