Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2d-x中ImageView的使用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。


Size size = Director::geTinstance()->getVisibleSize();@H_944_3@ ImageView* imageView = ImageView::create("ccicon.png");@H_944_3@ imageView->setPosition(Vec2(size.width /2,size.height /2));@H_944_3@ imageView->ignoreContentAdaptWithSize(false);@H_944_3@ imageView->setScale9Enabled(true);@H_944_3@ imageView->setContentSize(Size(100,100));@H_944_3@ imageView->setCapInsets(Rect(20,20,20));//设置伸缩后的内框大小@H_944_3@ imageView->setTouchEnabled(true);@H_944_3@ imageView->addTouchEventListener([=](Ref* sender,cocos2d::ui::Widget::TouchEventType typE){@H_944_3@ if (type == cocos2d::ui::Widget::TouchEventType::ENDED)@H_944_3@ {@H_944_3@ if (imageView->isScale9Enabled())@H_944_3@ {@H_944_3@ imageView->setScale9Enabled(false);@H_944_3@ }@H_944_3@ else@H_944_3@ {@H_944_3@ imageView->setScale9Enabled(true);@H_944_3@ }

}@H_944_3@ });

this->addChild(imageView);

@H_944_3@

//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的使用所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。