美文网首页
居中显示layer

居中显示layer

作者: nhfc99 | 来源:发表于2017-07-14 19:35 被阅读0次

void Nhf::initData()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 VisibleOrigin = Director::getInstance()->getVisibleOrigin();

// add your codes here...
auto bgView = LayerColor::create(cocos2d::Color4B(126, 213, 249, 255), visibleSize.width, visibleSize.height);

// bgView->setIgnoreAnchorPointForPosition(false);
bgView->setAnchorPoint(Vec2(0, 0));
bgView->setPosition(Vec2(VisibleOrigin.x, VisibleOrigin.y));
this->addChild(bgView);

auto *button = cocos2d::ui::Button::create("HelloWorld.png");
button->setContentSize(cocos2d::Size());
button->addClickEventListener(CC_CALLBACK_1(Nhf::ButtonClick, this));
button->setIgnoreAnchorPointForPosition(false);
button->setPosition(Vec2(VisibleOrigin.x + visibleSize.width/2, VisibleOrigin.y + visibleSize.height/2));
this->addChild(button);

}

相关文章

网友评论

      本文标题:居中显示layer

      本文链接:https://www.haomeiwen.com/subject/qipohxtx.html