cocos 3.4 十进制秒数 转换为时间并用 LabelAtlas显示

前端之家收集整理的这篇文章主要介绍了cocos 3.4 十进制秒数 转换为时间并用 LabelAtlas显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
	//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

猜你在找的Cocos2d-x相关文章