-
Book Overview & Buying
-
Table Of Contents
Cocos2d-x cookbook
By :
In this recipe, we will explain the slider. The slider will be used for tasks such as changing the volume of the sound or music. Cocos2d-x has a Slider class for it. If we use this class, we can create a slider easily.
So, let's prepare the images of the slider before we start. Please add these images in the Resouces/res folder.
sliderTrack.png: Background of the slider

sliderThumb.png: Image to move the slider

Let's create a slider by using the Slider class. First, you will generate a slider instance by using the sliderTrack.png image and the sliderThumb.png image. You will also specify the callback function as a lambda expression by using the addEventListener method when the slider value is changed.
auto slider = ui::Slider::create("res/sliderTrack.png",
"res/sliderThumb.png");
slider->setPosition(size/2);
this->addChild(slider);
slider->addEventListener([](Ref* sender, ui::Slider::EventType
type){
auto slider = dynamic_cast<ui...
Change the font size
Change margin width
Change background colour