A few people have asked this question recently. If you'd also like some extra information on volume sliders for your games then this post might help you
You can use a sprite to make a slider. Choose a length of slider, x. This can be anywhere from 2 pixels to 480 pixels, though the larger it is the more control the player has on setting the sound. Now define where the slider is, for example my slider will be 120 pixels long, and will be in position x=0 to x=120. The y co-ordinate is irrelevant. Now construct a script on the slider sprite, the slider should be something like a small circle the player can drag.
when gf clicked Forever If <<touching [mouse-pointer v]?> and <mouse down?>> if <<(mouse x) > (-1)> and <(mouse x) < (181)>> Set x to (mouse x) end end if <(x position) < (0)> Set x to (0) end if <(x position) > (180)> Set x to (180) endThis will make the slider go to the mouse within the confines of the boundary we defined, in this case 0 to 180 (note how to allow x=0 and x=180 I set the confines to x=-1 and x=181).
(((x position) / (180)) * (100))If your slider doesn't start at x=0, we'll need to change the script a bit, this time the length is still 180, but starts at x=20 and ends at x=200:
((((x position) - (20)) / (180)) * (100))And thus the general formula for ANY starting x=n and length=l becomes:
((((x position) - (n)) / (l)) * (100))Set the volume % to this value and then you have a slider
when gf clicked forever Set volume to ((((x position) - (n)) / (l)) * (100)) %I hope this helps
Last edited by Prestige (2012-07-19 08:25:51)
Offline
Great guide!
Offline
LightFlash wrote:
Great guide!
Thanks
Offline
You should make a Scratch Wiki tutorial about this!
Offline
scimonster wrote:
You should make a Scratch Wiki tutorial about this!
That'd be nice, I don't think my username is activated on the wiki though!
Offline
Prestige wrote:
scimonster wrote:
You should make a Scratch Wiki tutorial about this!
That'd be nice, I don't think my username is activated on the wiki though!
Request an account.
Offline
scimonster wrote:
Request an account.
Thanks for the tip
Offline