相信玩过植物大战僵尸等类似游戏的同学对于道具倒计时都不陌生,这些倒计时在游戏开发中是如何制作出来的呢?本篇教程将告诉你Cocos2d-x中是如何制作道具倒计时的。
话不多说,直接进入正题,上代码:
//实现倒计时
this->_down_Label =CCLabelTTF::create();
CCString* downStr = CCString::createWithFormat("%d",this->_dowmTime);
this->_down_Label->setString(downStr->m_sString.c_str());
this->addChild(this->_down_Label,3);
this->_down_Label->setPosition(ccp(this->_shootCard->getPosition().x,this->_shootCard->getPosition().y));
this->_down_Label->setFontSize(30);
//更新倒计时
void GameLayer::downTime(float dt)
{
this->_dowmTime =this->_dowmTime -1;
CCString* downStr = CCString::createWithFormat("%d",this->_dowmTime);
this->_down_Label->setString(downStr->m_sString.c_str());
}
schedule(schedule_selector(GameLayer::downTime),1.0f);
接下来看一下运行效果图:
好了,本篇教程到这里就结束了,希望对各位同学有所帮助!
¥98.00
¥108.00
¥698.00
¥98.00