Theoretical basis
RadioButton is a two-state button of a specific type, similar to a check box. It can be used with radiobuttongroup to form a "group". Inherit from Abstractcheckbutton,abstractcheckbutton inherited from Widget.
Code section
void AddEventListener (const ccradiobuttoncallback &callback)
Registers a callback function that will be called when the radio button is selected or canceled.
BOOL IsSelected () const
Query whether the check box is selected.
void setselected (bool selected)
Changing the status of a check box to true causes the check box to be selected, or false to make the check box "unchecked"
void Loadtextures (const std::string &background,//background The name of the normal state picture.
Const std::string &backgroundselected,//Background Select the name of the state picture.
Const std::string &cross,//Tick The name of the selected state picture.
Const std::string &backgrounddisabled,//background disables state picture name.
Const std::string &frontcrossdisabled,//Check disable status picture name.
Texturerestype textype=texturerestype::local)//
Loads all textures and initializes a check box.
void Loadtexturebackground (const std::string &background, Texturerestype type=texturerestype::local)
Load background normal state texture
void loadtexturebackgroundselected (const std::string &backgroundselected, Texturerestype texType=TextureResType :: LOCAL)
Loading a picture of the background checked state texture
void Loadtexturefrontcross (const std::string &crosstexturename, Texturerestype textype=texturerestype::local)
Load tick the selected texture picture
void loadtexturebackgrounddisabled (const std::string &backgrounddisabled, Texturerestype texType=TextureResType :: LOCAL)
Load background disable state texture picture
void loadtexturefrontcrossdisabled (const std::string &frontcrossdisabled, Texturerestype texType=TextureResType :: LOCAL)
Load tick the disabled state texture picture
Virtual Size getvirtualrenderersize () const override
Get the dimensions of a virtual render node
Virtual Node * Getvirtualrenderer () override
The internal render node of the control. For example, a button's virtual render node is its texture node.
void Setzoomscale (float scale)
When the user presses the check box, the button zooms to a scale the last check box has a zoom value equal to (check box original size + _zoomscale)
float Getzoomscale () const
Returns a zoom ratio
Sprite * Getrendererbackground () const
Returns a render node in the normal state of the background
Sprite * getrendererbackgroundselected () const
Returns the render node of the background selection state
Sprite * Getrendererfrontcross () const
Returns the render node of the foreground normal state
Sprite * getrendererbackgrounddisabled () const
Returns a render node with a background disabled state
Sprite * getrendererfrontcrossdisabled () const
Returns the render node for the foreground disabled state
Instance:
Size widgetsize = _widget->getcontentsize (); //Create a radio button group_radiobuttongroup =radiobuttongroup::create (); _uilayer-AddChild (_radiobuttongroup); //Create the radio buttons Static Const intNumber_of_buttons =5; Startposx= Widgetsize.width/2.0f-((Number_of_buttons-1) /2.0f) *Button_width; for(inti =0; i < number_of_buttons; ++i) {RadioButton* RadioButton = Radiobutton::create ("Cocosui/radio_button_off.png","Cocosui/radio_button_on.png"); floatPosX = startposx + button_width *i; RadioButton->setposition (VEC2 (PosX, Widgetsize.height/2.0f+Ten)); RadioButton->setscale (1.2f); _radiobuttongroup-AddRadioButton (RadioButton); _uilayer-AddChild (RadioButton); }
Cocos Code Research (+) widget sub-class RadioButton learning Notes