cocos2d-x Slider的使用

前端之家收集整理的这篇文章主要介绍了cocos2d-x Slider的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


Size size = Director::getInstance()->getVisibleSize();
cocos2d::ui::Button* button = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");
button->setPosition(Vec2(size.width / 2,size.height / 2));
button->setPressedActionEnabled(true);
button->addClickEventListener([=](Ref* sender){//监听的一中方式
CCLOG("Button clicked,position = (%f,%f)",button->getPosition().x,
button->getPosition().y);
});
button->setName("button");
this->addChild(button);
button->setZoomScale(-0.5);

cocos2d::ui::Slider* slider = cocos2d::ui::Slider::create();
slider->loadBarTexture("sliderTrack.png");
slider->loadSlidBallTextures("sliderThumb.png","sliderThumb.png","");
slider->loadProgressBarTexture("sliderProgress.png");
slider->setPosition(Vec2(size.width / 2.0f,size.height / 2 - 50));
slider->addEventListener(CC_CALLBACK_2(HelloWorld::sliderEvent,this));
slider->setPercent(button->getZoomScale()* 100);
this->addChild(slider);


void HelloWorld::sliderEvent(Ref *pSender,cocos2d::ui::Slider::EventType type)
{
if (type == cocos2d::ui::Slider::EventType::ON_PERCENTAGE_CHANGED)
{
cocos2d::ui::Slider* slider = dynamic_cast<Slider*>(pSender);
int percent = slider->getPercent();
log("------->%d",percent);
Button* btn = (Button*)this->getChildByName("button");
float zoomScale = percent * 0.01;

} }

猜你在找的Cocos2d-x相关文章