zoukankan      html  css  js  c++  java
  • cocos代码研究(20)Widget子类LoadingBar学习笔记

    理论基础

    在一些操作中可视化指示进度条。显示给用户一个条表示操作已经完成了多少,继承自 Widget。

    代码实践

    static LoadingBar * create ()
    创建一个空的LoadingBar。

    static LoadingBar * create (const std::string &textureName, //LoadingBar背景纹理图片文件。
    float percentage=0) //显示的进度百分比。
    使用一个纹理和一个进度百分比创建一个LoadingBar。

    static LoadingBar * create (const std::string &textureName, //LoadingBar背景纹理图片文件。
    TextureResType texType, //LoadingBar背景纹理类型。
    float percentage=0) //显示的进度百分比。
    使用一个纹理、纹理类型和一个进度百分比创建一个LoadingBar。

    void setDirection (Direction direction)
    改变进度显示方向。

    Direction getDirection () const
    获取进度显示方向。

    void loadTexture (const std::string &texture, //LoadingBar背景纹理图片文件。
    TextureResType texType=TextureResType::LOCAL)
    LoadingBar载入背景纹理。

    void setPercent (float percent)
    改变LoadingBar的当前进度。

    float getPercent () const
    获取LoadingBar当前的进度。

    void setScale9Enabled (bool enabled)
    是否开启九宫格渲染。

    bool isScale9Enabled () const
    请求LoadingBar是否开启了九宫格渲染。

    void setCapInsets (const Rect &capInsets)
    设置CapInsets。 只有当开启九宫格渲染后才需要设置。

    const Rect & getCapInsets () const
    请求LoadingBar的capInsets。

    实例:

    // Create the loading bar
    LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderThumb.png");
    loadingBar->setTag(0);
    loadingBar->ignoreContentAdaptWithSize(false);
    //loadingBar->setScale9Enabled(true);
    loadingBar->setCapInsets(Rect(0, 0, 0, 0));
    loadingBar->setContentSize(Size(200, 80));
    loadingBar->setDirection(LoadingBar::Direction::LEFT);
    loadingBar->setPercent(100);
    loadingBar
    ->setTouchEnabled(true); loadingBar->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){   if (type == Widget::TouchEventType::ENDED) {     if (loadingBar->isScale9Enabled())     {       loadingBar->setScale9Enabled(false);     }     else       loadingBar->setScale9Enabled(true);     } }); loadingBar->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
  • 相关阅读:
    Codeforces Round #333 (Div. 1)--B. Lipshitz Sequence 单调栈
    UVALive 7148 LRIP 14年上海区域赛K题 树分治
    UVAlive7141 BombX 14年上海区域赛D题 线段树+离散化
    VK Cup 2015
    Codeforces Round #326 (Div. 1)
    Codeforces Round #216 (Div. 2) E. Valera and Queries 树状数组 离线处理
    Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP
    Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新
    java连接mysql出现The server time zone value '�й���׼ʱ��' is unrecognized or represents more than...
    Java Date转Json报错解决方案
  • 原文地址:https://www.cnblogs.com/damowang/p/4861800.html
Copyright © 2011-2022 走看看