Fix Interval of a slider

Hello,

Do you know how fix the interval of a slider ?

By default, its 0 -> 100 percent, but i want 20 -> 60.

It is possible ?

This is my code, i try the method “slider->setSizePercent(Vec2(20, 60);” but it does not work.

Slider* slider = Slider::create();
slider->loadBarTexture(“sliderTrack.png”);
slider->loadSlidBallTextures(“sliderThumb.png”, “sliderThumb.png”, “”);
slider->loadProgressBarTexture(“sliderProgress.png”);
slider->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height / 2.0f));/* + slider->getSize().height * 2.0f*/
slider->addEventListener(CC_CALLBACK_2(EcranOptions::sliderEvent, this));
slider->setSizePercent(Vec2(20, 60);
this->addChild(slider);

In advance thanks,

setSizePercent only sets the size of the widget in relation to it’s overall size.

You cannot set a user defined min and max value. Just handle it within the callbacks of the slider, so a user can only drag to those values.

If you want to have such a slider(including disabled graphics for the values lower than min and higher than max), you would have to implement your own slider or derive from the base slider…

There is/was an extension for such sliders: http://www.cocos2d-x.org/hub/1

1 Like

Ok, thanks a lot for your answer.