效果图是这样
Size size = Director::getInstance()->getVisibleSize();//表示获得视口(可视区域)的大小
Vec2 origin = Director::getInstance()->getVisibleOrigin();//表示可视区域的起点坐标
auto* background = Sprite::create("background.jpg");
background->setPosition(size.width / 2, size.height / 2);
background->setScale(0.7f);//让背景图缩小尺寸
addChild(background, 0);
auto* button1 = Sprite::create("button1.png");
button1->setPosition(550, size.height / 2);
button1->setScale(0.6f);
addChild(button1, 1);
auto* pButton2 = MenuItemImage::create("button1.png",//按钮正常状态下图片
"button2.png",//按钮被按下时显示的图片
this,//当前场景
menu_selector(HelloWorld::menu));//响应用户单机的操作
auto* button2 = Menu::create(pButton2, NULL);//创建菜单
button2->setAnchorPoint(Vec2(0,0));
button2->setPosition(550, size.height / 2 - 60);
button2->setScale(0.6f);//缩放
addChild(button2);
auto* pButton3 = MenuItemImage::create("button1.png",
"button2.png",
this,
menu_selector(HelloWorld::menu));
auto* label3 = LabelTTF::create("start", "Arial", 40);//按钮所使用的标签
auto* pLabel3 = MenuItemLabel::create(label3, this, menu_selector(HelloWorld::menu));//创建文字菜单
auto* button3 = Menu::create(pButton3, pLabel3, NULL);//将按钮菜单和文字菜单加入到菜单对象中
button3->setAnchorPoint(Vec2(0, 0));
button3->setPosition(550, size.height / 2 - 120);
button3->setScale(0.6f);
addChild(button3);
auto* renwu = Sprite::create("renwu.png");
renwu->setPosition(0, 0);
renwu->setAnchorPoint(Vec2(0, 0));
renwu->setScale(0.5f);
addChild(renwu, 2);