Cocos2d-x中ImageView的使用

Cocos2d-x中ImageView的使用,第1张

概述 Size size = Director::getInstance()->getVisibleSize();  ImageView* imageView = ImageView::create("ccicon.png");  imageView->setPosition(Vec2(size.width /2,size.height /2));  imageView->ignoreConten 

Size size = Director::getInstance()->getVisibleSize();
ImageVIEw* imageVIEw = ImageVIEw::create("ccicon.png");
imageVIEw->setposition(Vec2(size.wIDth /2,size.height /2));
imageVIEw->ignoreContentAdaptWithSize(false);
imageVIEw->setScale9Enabled(true);
imageVIEw->setContentSize(Size(100,100));
imageVIEw->setCAPInsets(Rect(20,20,20));//设置伸缩后的内框大小
imageVIEw->settouchEnabled(true);
imageVIEw->addtouchEventListener([=](Ref* sender,cocos2d::ui::Widget::touchEventType type){
if (type == cocos2d::ui::Widget::touchEventType::ENDED)
{
if (imageVIEw->isScale9Enabled())
{
imageVIEw->setScale9Enabled(false);
}
else
{
imageVIEw->setScale9Enabled(true);
}

}
});

this->addChild(imageVIEw);


//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);

总结

以上是内存溢出为你收集整理的Cocos2d-x中ImageView的使用全部内容,希望文章能够帮你解决Cocos2d-x中ImageView的使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1077428.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存