Cocos2d-x Layout的使用二

Size size = Director::getInstance()->getVisibleSize();
Layout* root = Layout::create();
root->setContentSize(Size(500,400));
root->setLayoutType(LayoutType::ABSOLUTE);
root->setPosition(Vec2(size.width /2,size.height /2));
root->setBackGroundImage("green_edit.png");
root->setAnchorPoint(Point(0.5f,0.5f));//设置以root的中心为锚点
root->setBackGroundImageScale9Enabled(true);//这句很重要,设置铺面root

this->addChild(root);


Button* button = Button::create("animationbuttonnormal.png", "animationbuttonpressed.png");
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
root->getContentSize().height - button->getContentSize().height / 2.0f));
root->addChild(button);


Button* titleButton = Button::create("backtotopnormal.png", "backtotoppressed.png");
titleButton->setTitleText("xxxxxxxx");
titleButton->setPosition(Vec2(root->getContentSize().width / 2.0f , root->getContentSize().height / 2.0f));
root->addChild(titleButton);


Button* button_scale9 = Button::create("button.png", "buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vec2(root->getContentSize().width - button_scale9->getContentSize().width / 2.0f ,
button_scale9->getContentSize().height / 2.0f));
root->addChild(button_scale9);

你可能感兴趣的:(Cocos2d-x Layout的使用二)