Cocos2d-x3.3final (3) button common member function (c + +)

Source: Internet
Author: User
Tags addchild

Button * Button = Button::create ("Cocosui/animationbuttonnormal.png"); //New button

button* button = button::create ("Cocosui/button.png", "cocosui/buttonhighlighted.png"); //New button

Button->addtoucheventlistener (Cc_callback_2 (uibuttontest::touchevent, this)); //Set touch events and action targets for buttons (inherit from widget)

Button->setzoomscale (0.4f);

3.3 New function, button click will be larger for the original coefficient 1+ here the coefficient of 0.4,

Can be used with sliders, slider->getpercent ()

FLOAT Zoomscale = percent * 0.01;

Btn->setzoomscale (Zoomscale);


Button->setpressedactionenabled (TRUE); //Set button to enable click-to-zoom effect

Button->setopacity (100); //Inherit from node, set node transparency, 0 completely transparent, 100 completely opaque

Button->loadtexturenormal ("Cocosui/animationbuttonnormal.png"); //load Normal fill chart

Btn->loadtexturepressed ("Cocosui/animationbuttonpressed.png"); //Load Fill chart with push button

Button->setscale9enabled (TRUE); //Whether to enable the nine Gongge display mode

Button->setcontentsize (Size (150, 70)); //Set the size of the button (inherited from node)

Button->setposition (VEC2 (widgetsize.width/2.0f, widgetsize.height/2.0f)); //Set the position of the button (inherited from node)

Button->runaction (Sequence::create (fadein::create (0.5), delaytime::create (1.0), fadeout::create (0.5), nullptr) ); //Execute an action or action sequence (inherited from node)

Four touch states of the touch event handler:

Widget::toucheventtype::ended:

Widget::toucheventtype::canceled:

Widget::toucheventtype::moved:

Widget::toucheventtype::began:


Button2->setname ("normal"); //Set name

Button->setcolor (Color3b::green); //Set the color of the button

Button2->setposition (button->getposition () + VEC2 (100,0)); //(set position parameter can be added by using this)

Btn2->setanchorpoint (VEC2 (0,0.5)); //Set Anchor point

Button->settitletext ("Title button!"); //Set the caption of the button

Button->settitlecolor (Color3b::yellow); //Title Color

Button->setflippedx (TRUE); //Set button to flip in the x direction

Auto label = Button->gettitlerenderer (); The caption renderer for the//button is a label

Button->runaction (Repeatforever::create (Sequence::create (Scaleto::create (1.0f, 1.2f),
Scaleto::create (1.0f, 1.0f), nullptr)); //button has been repeatedly inflated 1.2 times times and back to the original action

{ //Click Delete yourself

Layout *layout = Layout::create ();
Layout->setcontentsize (Widgetsize * 0.6f);
Layout->setbackgroundcolor (Color3b::green);
Layout->setbackgroundcolortype (Layout::backgroundcolortype::solid);
Layout->setbackgroundcoloropacity (100);
Layout->setposition (Size (WIDGETSIZE.WIDTH/2, WIDGETSIZE.HEIGHT/2));
Layout->setanchorpoint (Vec2::anchor_middle);
Layout->settag (N);
_uilayer->addchild (layout);


button* button = button::create ("Cocosui/animationbuttonnormal.png",
"Cocosui/animationbuttonpressed.png");
Button->setposition (VEC2 (Layout->getcontentsize () width/2.0f, Layout->getcontentsize (). height/2.0f));
Button->addtoucheventlistener (This, Toucheventselector (uibuttontest::touchevent));
Button->addtoucheventlistener (Cc_callback_2 (uibuttontestremoveself::touchevent, this));
Layout->addchild (button);


Auto layout = _uilayer->getchildbytag (N);
Layout->removefromparentandcleanup (TRUE); //Delete yourself and note that the button is placed in layout

}


Button->ignorecontentadaptwithsize (FALSE); //Inherit from widget, set parameter to true,setcontentsize invalid, size equals function getvirtualrenderersize return value

{//Set the effect of the button caption

Label *title = Button->gettitlerenderer ();
Title->enableshadow (Color4b::black,size (2,-2)); //Shadow

Title2->enableoutline (Color4b::green, 3); //it only works on IOS and Android when your use System fonts

}


Button2->setnormalizedposition (VEC2 (0.8f, 0.5f)); //equivalent

void Setnormalizedposition (Vec2 pos) {
Size s = getParent ()->getcontentsize ();
_position = pos * s;
}



Cocos2d-x3.3final (3) button common member function (c + +)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.