http://www.cocos2dev.com/?p=90
游戏中要用到分数是动态增加的,而不是瞬间加上去的。
bool HelloWorld::init() {
if ( !CCLayer::init() ) {
return false;
}
visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//
lblScore=CCLabelTTF::create("d","Arial",40);
lblScore->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
addChild(lblScore);
//
this->schedule(schedule_selector(HelloWorld::runChangeScore),0.2f);
//
return true;
}
void HelloWorld::runChangeScore(float delta) {
//temScore:当前分数;
//mScore:最后的显示分数;
int temScore=atoi(lblScore->getString());
int addScore=mScore-temScore;
if(abs(addScore)>10) {
temScore+=addScore/10;
}else if(abs(addScore)>2 &&abs(addScore)<=10){
temScore+=addScore/abs(addScore);
}else{
temScore=mScore;
}
CCString* str=CCString::createWithFormat("%d",temScore);
lblScore->setString(str->getCString());
}