This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-19 08:06:01

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Need help with custom volume sliders?

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  smile

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)
end 
This 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).

Now, we'll need to set the sound to this value. As the sound works as a percentage, we can change this slider value to a % value too. As my slider is 180 pixels long, to find out the % we can use this:


(((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  smile

when gf clicked
forever
Set volume to ((((x position) - (n)) / (l)) * (100)) %
I hope this helps  smile

Last edited by Prestige (2012-07-19 08:25:51)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#2 2012-07-19 08:30:49

LightFlash
Scratcher
Registered: 2012-07-17
Posts: 75

Re: Need help with custom volume sliders?

Great guide!  big_smile

Offline

 

#3 2012-07-19 10:43:01

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Need help with custom volume sliders?

LightFlash wrote:

Great guide!  big_smile

Thanks  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#4 2012-07-19 11:08:10

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Need help with custom volume sliders?

You should make a Scratch Wiki tutorial about this!

Offline

 

#5 2012-07-19 12:31:13

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Need help with custom volume sliders?

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!  tongue


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#6 2012-07-19 12:35:51

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Need help with custom volume sliders?

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!  tongue

Request an account.  wink

Offline

 

#7 2012-07-19 13:00:21

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Need help with custom volume sliders?

scimonster wrote:

Request an account.  wink

Thanks for the tip  tongue


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

Board footer