本文整理汇总了C++中ImageView::getPositionPercent方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageView::getPositionPercent方法的具体用法?C++ ImageView::getPositionPercent怎么用?C++ ImageView::getPositionPercent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageView
的用法示例。
在下文中一共展示了ImageView::getPositionPercent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool UIImageViewTest_ContentSize::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
Text* alert = Text::create("ImageView ContentSize Change", "fonts/Marker Felt.ttf", 26);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
_uiLayer->addChild(alert);
Text *status = Text::create("child ImageView position percent", "fonts/Marker Felt.ttf", 16);
status->setColor(Color3B::RED);
status->setPosition(Vec2(widgetSize.width/2, widgetSize.height/2 + 80));
_uiLayer->addChild(status,20);
// Create the imageview
ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
imageView->setScale9Enabled(true);
imageView->setContentSize(Size(200, 80));
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f ));
ImageView* imageViewChild = ImageView::create("cocosui/buttonHighlighted.png");
imageViewChild->setScale9Enabled(true);
imageViewChild->setSizeType(Widget::SizeType::PERCENT);
imageViewChild->setPositionType(Widget::PositionType::PERCENT);
imageViewChild->setSizePercent(Vec2::ANCHOR_MIDDLE);
imageViewChild->setPositionPercent(Vec2::ANCHOR_MIDDLE);
imageViewChild->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f));
ImageView* imageViewChild2 = ImageView::create("cocosui/buttonHighlighted.png");
imageViewChild2->setScale9Enabled(true);
imageViewChild2->setSizeType(Widget::SizeType::PERCENT);
imageViewChild2->setPositionType(Widget::PositionType::PERCENT);
imageViewChild2->setSizePercent(Vec2::ANCHOR_MIDDLE);
imageViewChild2->setPositionPercent(Vec2::ANCHOR_MIDDLE);
imageViewChild->addChild(imageViewChild2);
imageView->addChild(imageViewChild);
imageView->setTouchEnabled(true);
imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
if (type == Widget::TouchEventType::ENDED) {
float width = CCRANDOM_0_1() * 200 + 50;
float height = CCRANDOM_0_1() * 80 + 30;
imageView->setContentSize(Size(width, height));
imageViewChild->setPositionPercent(Vec2(CCRANDOM_0_1(), CCRANDOM_0_1()));
status->setString(StringUtils::format("child ImageView position percent: %f, %f",
imageViewChild->getPositionPercent().x, imageViewChild->getPositionPercent().y));
}
});
_uiLayer->addChild(imageView);
return true;
}
return false;
}