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

#1 2012-07-19 00:23:52

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

sliders

how do i set music volume to a slider?

Offline

 

#2 2012-07-19 00:25:04

maxdoss
Scratcher
Registered: 2010-07-27
Posts: 1000+

Re: sliders

I don't know. I'm not even sure the volume button works. Maybe set the variable to sound.


It's my birthday. Deal with it.

Offline

 

#3 2012-07-19 00:28:39

Appletini
New Scratcher
Registered: 2012-07-18
Posts: 23

Re: sliders

Make a variable, "Music Volume". Expand it to slider size. Then, add this script to any sprite:

when flag clicked
forever
set volume to (Music Volume) %

Offline

 

#4 2012-07-19 07:19:39

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

Re: sliders

If you want to know how to set the value, check out my (jontmy00; my alt) project that was remixed here.

Offline

 

#5 2012-07-19 07:52:45

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

Re: sliders

You can also 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.


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


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

Last edited by Prestige (2012-07-19 08:03:57)


"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