Ejemplo n.º 1
0
 void LoadingBarReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
 {
     WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
     
     LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
     this->beginSetBasicProperties(widget);
     float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
     int percent = loadingBar->getPercent();
     
     stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
     
     for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
         std::string key = stChildArray[i].GetName(cocoLoader);
         std::string value = stChildArray[i].GetValue(cocoLoader);
         
         //read all basic properties of widget
         CC_BASIC_PROPERTY_BINARY_READER
         //read all color related properties of widget
         CC_COLOR_PROPERTY_BINARY_READER
         
         else if (key == P_Scale9Enable) {
             loadingBar->setScale9Enabled(valueToBool(value));
         }
         else if (key == P_TextureData){
             
             stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
             std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
             
             Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
             
             std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
             
             loadingBar->loadTexture(backgroundValue, imageFileNameType);
             
         }
         else if(key == P_CapInsetsX){
             capsx = valueToFloat(value);
         }else if(key == P_CapInsetsY){
             capsy = valueToFloat(value);
         }else if(key == P_CapInsetsWidth){
             capsWidth = valueToFloat(value);
         }else if(key == P_CapInsetsHeight){
             capsHeight = valueToFloat(value);
         }else if(key == P_Direction){
             loadingBar->setDirection((LoadingBar::Direction)valueToInt(value));
         }else if(key == P_Percent){
             percent = valueToInt(value);
         }
         
     } //end of for loop
     
     if (loadingBar->isScale9Enabled()) {
         loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
     }
     loadingBar->setPercent(percent);
     this->endSetBasicProperties(widget);
 }
Ejemplo n.º 2
0
void UI::LoadingBarUpdate(float dt){
    LoadingBar *lb =dynamic_cast<LoadingBar*>(getChildByTag(1));
    CCASSERT(lb, "the childer with tag 1 is not a loadingBar Class");
    float per=lb->getPercent()+0.5f;
    lb->setPercent(per);
    if (per>=100) {
        per=100;
        unschedule("LoadingBarUpdate");
    }
}