G
gmproduct
Guest
Does anyone know if anyone has created a code or way of making a volume control turn knob as apposed to a volume control slider?
Cheers
Graeme
Cheers
Graeme
How would you want to rotate it? In other words, what is the specific action a player would take to interact and rotate the knob?Does anyone know if anyone has created a code or way of making a volume control turn knob as apposed to a volume control slider?
Cheers
Graeme
I haven't done this before, so no guarantees, but my first attempt would be to lock the angle difference between the mouse position and the object when the left button is pressed, and then update the button's angle based upon the updated angle from button to mouse as the mouse moves so that the difference remains the same.hi samspade,
I need to rotate it by grabbing the volume knob sprite using mouse left press button then turning it from left to right in order to increase the volume, reversing would decrease the sound, much like you would do with a record player or radio volume control
have you any idea how I would go about this?
thanks for your reply
//create
mouse_x_prev = 0;
mouse_click = false
volume = 50; //out of 100
//note: a non-1 (eg 50/100) value at the start of the game will cause a pop
//for this code I'm using 50, but you should use 100
image_angle = 0; //no need for this line, really, if 0
//change depending on how your sprite is drawn or how you want it to point
//step
if point_collision(mouse_x, mouse_y, id, true, false) { //id should work, it would be the instance of the knob
if (mouse_check_button_pressed(mb_left)) mouse_click = true;
}
if mouse_click {
volume += (mouse_x - mouse_x_prev) / 20; //the smaller this number, the faster volume changes
volume = clamp(volume, 0, 100); //you can also set a max volume
}
if (mouse_check_button_released(mb_left)) mouse_click = false;
mouse_x_prev = mouse_x;
audio_master_gain(volume / 100); //or out of max volume
image_angle = (50 - volume) * 2; //put a multiplier depending on how you want it to turn
//with a times-2 multiplier, your angle will be between 100 and -100 degrees
//since 50 is halfway, change as needed
//recommended to set a variable for this value
Yes, I would use the method I suggested in my first post for this - except I wouldn't have an invisible slider, I would do it all in the circular control knob and that if you wanted to do it with the mouse buttons, rather than moving the mouse, you would adjust the angle with those instead of calculating the angle of movement.Hi Samspade and SoapSud39
Thanks for your help, I'll have a go with the code you suggested SoapSud39... I was looking at this Youtube video from GravityShift games:
GameMaker Tutorial - Sound and Sliders
I have used the code he teaches in this video before and it worked OK, I was thinking about using the slider and slider-knob within my project but making these items invisible and possibly controlling the slider-knob movement with the circular volume control knob that I want to control with a left/ right mouse pressed function... is this possible and have you or anyone any ideas on how I would go about doing this as I imagine there would have to be some code that would have to be changed and others that would have to be created, or would this make things more complicated?