//layer 指针,时间中点位置,单位 秒 (已经换算) static void ShowTime(cocos2d::Node* parent,Vec2 vec,int time); void Memory::GameHelper::ShowTime(cocos2d::Node* parent,int time) { const int TIMENUM = 5; char Strtime[TIMENUM][16] = {"","","/",""}; int HandleShowTime[TIMENUM] = {}; HandleShowTime[0] = (time / 600) % 10; HandleShowTime[1] = (time / 60) % 10; HandleShowTime[2] = 0; HandleShowTime[3] = ((time%60)/10); HandleShowTime[4] = time % 10; string strTime = ""; for (int i = 0; i < TIMENUM; i++) { if (i!= 2) { sprintf(Strtime[i],"%d",HandleShowTime[i]); } strTime += Strtime[i]; } LabelAtlas * LableNum = dynamic_cast<LabelAtlas*>(parent->getChildByTag(TIMELABLETAG)); if (LableNum) { LableNum->setString(strTime.c_str()); } else { LableNum = CREATE_LABEL_ATLAS("00/00","TimeNumber.png",22,27,'/'); LableNum->setPosition(vec); LableNum->setAnchorPoint(Vec2(0.5f,0.5f)); parent->addChild(LableNum,1,TIMELABLETAG); } }
CREATE_LABEL_ATLAS为自定义宏
原文链接:https://www.f2er.com/cocos2dx/343924.html