cocos代碼研究(16)Widget子類RadioButton學習筆記

來源:互聯網
上載者:User

標籤:

理論基礎

RadioButton是一種特定類型的兩狀態按鈕,它與複選框相似。它可以 和RadioButtonGroup一起使用,形成一個"組"。繼承自AbstractCheckButton,AbstractCheckButton繼承自Widget。

代碼部分

void addEventListener (const ccRadioButtonCallback &callback)
註冊一個回呼函數, 它將在選項按鈕被選中或者取消的時候被調用.

bool isSelected () const
查詢是否選中複選框。

void setSelected (bool selected)
修改複選框的狀態 設定True會使複選框變為“選中狀態”,否則傳False會使複選框變為“未選中狀態”

void loadTextures (const std::string &background,//背景普通狀態圖片的名字。
const std::string &backgroundSelected,//背景選擇狀態圖片的名字。
const std::string &cross,//勾選選中狀態圖片的名字。
const std::string &backgroundDisabled,//背景禁用狀態圖片名字。
const std::string &frontCrossDisabled,//勾選禁用狀態圖片名字。
TextureResType texType=TextureResType::LOCAL)//
載入所有紋理並初始化一個複選框。

void loadTextureBackGround (const std::string &backGround, TextureResType type=TextureResType::LOCAL)
載入背景普通狀態紋理

void loadTextureBackGroundSelected (const std::string &backGroundSelected, TextureResType texType=TextureResType::LOCAL)
載入背景選中狀態紋理的圖片

void loadTextureFrontCross (const std::string &crossTextureName, TextureResType texType=TextureResType::LOCAL)
載入勾選選中狀態的紋理圖片

void loadTextureBackGroundDisabled (const std::string &backGroundDisabled, TextureResType texType=TextureResType::LOCAL)
載入背景禁用狀態紋理的圖片

void loadTextureFrontCrossDisabled (const std::string &frontCrossDisabled, TextureResType texType=TextureResType::LOCAL)
載入勾選禁用狀態的紋理圖片

virtual Size getVirtualRendererSize () const override
擷取虛擬渲染節點的尺寸

virtual Node * getVirtualRenderer () override
控制項的內部渲染節點。 例如,一個按鈕的虛擬渲染節點是它的紋理節點。

void setZoomScale (float scale)
當使用者按下複選框時,按鈕將會縮放到一個比例 最後複選框的縮放值等於(複選框原尺寸+ _zoomScale)

float getZoomScale () const
返回一個縮放比例

Sprite * getRendererBackground () const
返回背景普通狀態的渲染節點

Sprite * getRendererBackgroundSelected () const
返回背景選擇狀態的渲染節點

Sprite * getRendererFrontCross () const
返回前景普通狀態的渲染節點

Sprite * getRendererBackgroundDisabled () const
返回背景禁用狀態的渲染節點

Sprite * getRendererFrontCrossDisabled () const
返回前景禁用狀態的渲染節點

執行個體:

        Size widgetSize = _widget->getContentSize();                // Create a radio button group        _radioButtonGroup = RadioButtonGroup::create();        _uiLayer->addChild(_radioButtonGroup);                // Create the radio buttons        static const int NUMBER_OF_BUTTONS = 5;        startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * BUTTON_WIDTH;        for(int i = 0; i < NUMBER_OF_BUTTONS; ++i)        {            RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png");            float posX = startPosX + BUTTON_WIDTH * i;            radioButton->setPosition(Vec2(posX, widgetSize.height / 2.0f + 10));            radioButton->setScale(1.2f);            _radioButtonGroup->addRadioButton(radioButton);            _uiLayer->addChild(radioButton);        }

 

cocos代碼研究(16)Widget子類RadioButton學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.