O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a volume slider

Sometimes, it is good to add a volume slider to your game so that the player has the freedom to reduce it if he or she finds it a little too loud. In this section, we will discuss how to add a volume slider to our game in the options menu.

Getting ready

To add a volume slider, we will need to import the sliderBase.png and sliderHandle.png files into our project.

How to do it…

Right after where we added the toggle button to mute the audio, we will add the following code:

 //slider CCSpriteFrame *sliderBase = [CCSpriteFrame frameWithImageNamed:@"sliderBase.png"]; CCSpriteFrame *sliderHandle = [CCSpriteFrame frameWithImageNamed:@"sliderHandle.png"]; CCSlider *slider = [[CCSlider alloc]initWithBackground:sliderBase andHandleImage:sliderHandle ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required