Sound looping on object despite same events as other objects?

fumpo

Member
I have a menu button object for each option (o_start, o_controls, o_rules, o_about, o_exit) in my main menu, but they all have the exact same Left Pressed and Mouse Enter events, which can be found below. A screenshot of the main menu can be found below as well. But for some reason, the 'Exit' button in my r_main room plays its Mouse Enter sound constantly. Why could this be?

I'm happy to provide any additional information about my environment if need be.

Left Pressed
GML:
if mouse_check_button_pressed(mb_left){
    audio_play_sound(menu_go,1,false)   
}
Mouse Enter
GML:
if position_meeting(mouse_x,mouse_y,self){
    audio_play_sound(menu_move,1,false)   
}
issue.PNG
 
With that code the sound will loop the entire time you have the mouse on the text since it's finding position_meeting every step

It needs to set a variable to true an false like:


GML:
if position_meeting(mouse_x,mouse_y,self) and button_touched = false{
   
    audio_play_sound(menu_move,1,false)
    button touched = true;
}


if !position_meeting(mouse_x,mouse_y,self){
    button touched = false;
}
That means it will only play in the step it's contacted because it immediately sets button touched to true, any time the mouse isn't touching the button that will set back to false so it can be moved back and engaged again
 
Last edited:

Nidoking

Member
With that code the sound will loop the entire time you have the mouse on the text since it's finding position_meeting every step
Not if it's in a Mouse Enter event. Then it will only play if the mouse enters it. The position_meeting is completely irrelevant and can be removed.

I don't see anything here that would cause the problem described, so I believe the problem is in a part you haven't posted. What are all of the audio_play_sound calls in your entire game, and where are they? How have you determined that the source of the sound is a Mouse Enter event? Did you use the debugger?
 
Not if it's in a Mouse Enter event. Then it will only play if the mouse enters it. The position_meeting is completely irrelevant and can be removed.

I don't see anything here that would cause the problem described, so I believe the problem is in a part you haven't posted. What are all of the audio_play_sound calls in your entire game, and where are they? How have you determined that the source of the sound is a Mouse Enter event? Did you use the debugger?
Ah

Didn't notice that and because of the use of that check I assumed OP was doing this in the step event
 
Top