zoukankan      html  css  js  c++  java
  • 【转】cocos2d-x 模仿计时器效果,动态增加分数——2013-08-25 16

    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());
    }

  • 相关阅读:
    Python之描述器
    Python魔术方法
    Python二分法查找
    Qt连接oracle
    oracle11g下载安装
    Qwidget,QMainWindow ,Qdialog
    动态库
    静态库
    Qt翻译文件
    Qt 日志界面类
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3280973.html
Copyright © 2011-2022 走看看