Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: C.T.C.B on Fri 03/05/2013 04:45:41

Title: Problem(s) with Mouse Hotpoint in Room.
Post by: C.T.C.B on Fri 03/05/2013 04:45:41
I have this code:
[embed=425,349]
function hNewGame_MouseMove()
{
  oNewGame.Graphic = 5;
  AudioChannel* Click = aMenuClick.Play(eAudioPriorityNormal, eOnce);
  Click.Volume = 50;
}
[/embed]

My Problems:
1) When the mouse is moved over oNewGame, which is the New Game Button on the menu, the click happens each time the mouse moves a pixel, whereas I want it to only play once.

2) I want the Graphic of oNewGame to go back to how it was if the mouse is not over it.
Title: Re: Problem(s) with Mouse Hotpoint in Room.
Post by: Khris on Fri 03/05/2013 11:18:12
Empty your function, add the room's RepExec event, then use this:
Code (ags) Select
Hotspot*old_h;

function room_RepExec() {
  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  if (h != old_h) {  // we have just moved over a hotspot or left one
    // new game
    if (h == hNewGame) {  // mouse moved over hNewGame
      oNewGame.Graphic = 5;
      AudioChannel* Click = aMenuClick.Play(eAudioPriorityNormal, eOnce);
      Click.Volume = 50;
    }
    else if (old_h == hNewGame) {  // mouse left hNewGame
      oNewGame.Graphic = 4;
    }

    // other buttons here

    old_h = h;
  }
}



(Also, just in case there are typos, try to fix them yourself this time using the manual and AGS's auto-complete feature :))

Edit: also, if you're going to use the same audio for all the buttons, the audio code can be typed once instead of separately for each button.
Just move it to
Code (ags) Select
    if (old_h.ID == 0) {  // mouse left hotspot 0 (no hotspot)
      AudioChannel ...
      ...
    }