Size widgetSize = Director: getInstance ()-> getWinSize (); Text * alert = Text: create ("Layout", "fonts/Marker Felt. ttf ", 30); alert-> setColor (Color3B (159,168,176); alert-> setPosition (Point (widgetSize. width/2.0f, widgetSize. height/2.0f-alert-> getSize (). height * 3.075f); addChild (alert); Layout * layout = Layout: create (); layout-> setSize (Size (widgetSize. width, widgetSize. height); // horizontal arrangement, similar to the linear layout-> setLayoutType (LAYOUT_RELATIVE) in Android;/* use the image as the background */layout-> setBackGroundImageScale9Enabled (true ); layout-> setBackGroundImage ("green_edit.png"); layout-> setPosition (Point (0, 0); addChild (layout); Button * button_TopLeft = Button: create ("animationbuttonnormal.png ", "identifier"); // When enabled, the click effect button_TopLeft> setPressedActionEnabled (true); layout-> addChild (button_TopLeft); RelativeLayoutParameter * rp_TopLeft = RelativeLayoutParameter: create (); rp_TopLeft-> setAlign (TAGS); button_TopLeft-> setLayoutParameter (rp_TopLeft); // top center horizontal Button * button_TopCenter = Button: create ("tags", "tags "); layout-> addChild (button_TopCenter);/* you can set the Button Size */button_TopCenter-> setScale9Enabled (true); button_TopCenter-> setSize (Size (150, 70 )); parameters * rp_TopCenter = values: create (); rp_TopCenter-> setAlign (values); button_TopCenter-> setLayoutParameter (rp_TopCenter); Button * button_TopRight = Button: create ("values ", "identifier"); layout-> addChild (button_TopRight); button_TopRight-> addTouchEventListener (this, toucheventselector (LayoutTest: touchEvent); role * rp_TopRight = credential: create (); rp_TopRight-> setAlign (rule); button_TopRight-> setLayoutParameter (rp_TopRight); // left center Button * button_LeftCenter = Button: create ("rule", "animationbuttonpressed.png "); layout-> addChild (button_LeftCenter); Parameters * rp_LeftCenter = centers: create (); rp_LeftCenter-> setAlign (centers); button_LeftCenter-> setLayoutParameter (rp_LeftCenter ); button_LeftCenter-> setPressedActionEnabled (true );
void LayoutTest::touchEvent(cocos2d::Ref *pSender, TouchEventType type){ switch (type) { case cocos2d::ui::TOUCH_EVENT_BEGAN: log("TOUCH_EVENT_BEGAN"); break; case cocos2d::ui::TOUCH_EVENT_MOVED: log("TOUCH_EVENT_MOVED"); break; case cocos2d::ui::TOUCH_EVENT_ENDED: log("TOUCH_EVENT_ENDED"); break; case cocos2d::ui::TOUCH_EVENT_CANCELED: log("TOUCH_EVENT_CANCELED"); break; default: break; }}